Rules

The following list gives an overview of which rights the PHP project reserves for itself, when choosing names for new internal identifiers. The definitive guide is the official » CODING STANDARDS:

  • PHP owns the top-level namespace but tries to find decent descriptive names and avoid any obvious clashes.

  • Function names use underscores between words, while class names use both the camelCase and PascalCase rules.

  • PHP will prefix any global symbols of an extension with the name of the extension. (In the past, there have been numerous exceptions to this rule.) Examples:

  • Iterators and Exceptions are however simply postfixed with "Iterator" and "Exception." Examples:

  • PHP reserves all symbols starting with __ as magical. It is recommended that you do not create symbols starting with __ in PHP unless you want to use documented magical functionality. Examples:

add a note add a note

User Contributed Notes 1 note

up
1
Anonymous
4 years ago
#### Rules for PHP identifiers

1. A variable starts with the $ sign, followed by the name of the variable.

2. A variable name must start with a letter or the underscore character.

3. A variable name can only contain alpha-numeric characters and underscores (A-z, 0-9, and _ ).

4. Identifiers are case sensitive. Therefore, a variable named $unicorn is different from a variable named $Unicorn, $uNicOrn, or $unicorN.

5. Identifiers can be any length.

6. An identifier name can’t be identical to any of PHP’s predefined keywords.
To Top