We are talking about the types for PHP data
- and read formats (literals).
Literals are data values that are explicitly spelled out in a PHP statement or expression.
In PHP the type of a variable is the type of its current value (It is not so in other programming languages.) Also, it is not necessary to declare the type for a variable (or define the value of a variable) before it is used. However, you should, at least, define a variable’s value before using it; otherwise, your script will error out with a warning.
NULL is a good value to use as a default value. You will understand why later.
When PHP sees a variable (or literal) in a statement the type will be assumed to be what makes sense for the context. For example, if you use an integer variable in a string expression, PHP will interpret that integer variable as a string.
There are three things which matter about a variable:
- its type
- its value
- whether it is set or not set
Surprisingly, #3 can be just as important. For example, after a form is submitted as the result of a button press, the variable corresponding to that button will be set. You may not care about its value; however, you’ll care that it was set. Use
isSet() to find out.
The PHP types are: integers, doubles, booleans,
NULL, strings, arrays, objects and resources.
- evaluates to
FALSEas a boolean
FALSEwhen tested with
- (when assigned to a variable which is passed as a function parameter) that variable is considered to be set
There are ways to coerce PHP into interpreting things to the type of your choice. See coercion.
Also see testing for the type.