Naming Conventions
Part of the Fundamentals section of Coddy's PHP journey — lesson 9 of 71.
Naming conventions are a set of guidelines that developers follow to make their code more readable and maintainable. Different programming languages often have different naming conventions. In PHP, variables are written in camelCase - the first word starts with a lowercase letter, and subsequent words are capitalized with no spaces or separators.
When writing a variable name be descriptive and use meaningful words. Also remember that all PHP variables must start with a dollar sign $.
For example
// Bad Naming
$user_name = "John";
$a = 10;
$b = "Hello";
$x = true;
// Good Naming
$age = 10;
$greeting = "Hello";
$isActive = true;
$userName = "John";Cheat sheet
In PHP, variables follow camelCase naming convention - the first word starts with a lowercase letter, and subsequent words are capitalized with no spaces or separators.
Variable names should be descriptive and meaningful. All PHP variables must start with a dollar sign $.
// Good naming examples
$age = 10;
$greeting = "Hello";
$isActive = true;
$userName = "John";Try it yourself
This lesson doesn't include a code challenge.
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Fundamentals
4Comparison & Logical Operators
Comparison OperatorsEquality & IdentityLogical Operators Part 1Logical Operators Part 2Recap - Simple Logic2Variables and Data Types
NumbersStrings and QuotesBooleansNaming ConventionsRecap - Variable InitEmpty VariablesString ConcatenationGetting User InputCast to Different Types5Conditional Logic
If StatementIf - ElseThe Ternary OperatorNull Coalescing OperatorSwitch StatementRecap - Making Decisions3Basic Operators
Arithmetic OperatorsModulo OperatorExponentiation OperatorCombined AssignmentIncrement/DecrementOperator PrecedenceRecap - Simple CalculationsString Operators