Identifier Naming Convention
The name given to an identifier is incredibly important. Identifier names should be easy to remember and relevant to the entity you are identifying. If you identify something with a generic or irrelevant term, or one which can easily become outdated, you risk ‘losing’ the entity you are referencing, making it unnecessarily difficult to include it in your expressions. Doing this can also make it harder for other people to understand your code in the future.
For example, if you want to identify six variables used to collect personal information about a customer, the following table demonstrates a good example of variable names alongside two poor examples.
Good Example | Bad Example 1 | Bad Example 2 |
---|---|---|
Surname | Name2 | Variable1 |
Forename | Name1 | Variable2 |
HouseNumber | Address1 | Variable3 |
StreetName | Address2 | Variable4 |
City | Address3 | Variable5 |
PostCode | Address4 | Variable6 |
The first character of an identifier name must be a valid non-digit. All subsequent characters can be either non-digit or numeric. The table below shows a full list of valid characters that may be used when creating identifiers.
Non-digit | Numeric |
---|---|
_ a b c d e f g h I j k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z | 0 1 2 3 4 5 6 7 8 9 |
Note the inclusion of underscore (_) as a valid non-digit number. This is the only non-digit character permitted when naming identifiers that is not an alphabetic character.
When using Expression Engine in conjunction with an external application, your identifiers cannot share a name with any keywords associated with that application. The keywords are locked for use by the external application, and any attempt to create an identifier with a conflicting name will fail.
Similarly, you cannot define an identifier with the same name as a built-in function, constant or any other type of existing identifier. Conflicting identifiers will cause your expressions to work incorrectly or unpredictably, and must be avoided.
<< Previous: Identifiers | Next: Case Sensitivity >>