Types and Variables Variables
Variables
•
All PHP variable names start with $ followed by a PHP identifier
•
A PHP identifier consists of letters, digits, and underscores,
but cannot start with a digit
PHP identifiers are case sensitive
•
In PHP, a variable does not have to be declared before it can be used
•
A variable also does not have to be initialised before it can be used,
although initialisation is a good idea
•
Uninitialized variables have a default value of their type depending on
the context in which they are used
Type Default Type Default
bool FALSE string empty string
int/float 0 array empty array
If there is no context, then the default value is NULL
(Not 100% true, e.g., $uninitialized-- is NULL not -1)
COMP284 Scripting Languages Lecture 3 Slide L3 – 21