Values & Types
Type hierarchy

Literal Types
| Category |
Types |
Values |
| Special |
Null (doc) |
null |
| Scalar |
Boolean (doc) |
true
false, False, FALSE |
| Scalar |
Integer (doc) |
-15
15, 0b1111, 0o17, 0xf |
| Scalar |
Float (doc) |
-1234.5
1234.5, 1.2345e3
0.0012, 1.2E-3 |
| Scalar |
String (doc) |
'Hello'
"Hello" |
| Compound |
Array (doc) |
[]
[1, 2, 3]
[1, '2', true]
['name' => 'Alice', 'email' => 'alice@ifpb.edu'] |
| Compound |
Object (doc) |
stdObject
PDO |
Pseudo-types: mixed, number, callback, void
Type Casting
- (int), (integer) - cast to integer
- (bool), (boolean) - cast to boolean
- (float), (double), (real) - cast to float
- (string) - cast to string
- (array) - cast to array
- (object) - cast to object
- (unset) - cast to NULL
echo (int) 1.5; //=> 1
echo (int) ""; //=> 0
echo (int) true; //=> 1
| Expression |
gettype() |
empty() |
is_null() |
isset() |
boolean : if($x) |
$x = ""; |
string |
TRUE |
FALSE |
TRUE |
FALSE |
$x = null; |
NULL |
TRUE |
TRUE |
FALSE |
FALSE |
var $x; |
NULL |
TRUE |
TRUE |
FALSE |
FALSE |
$x is undefined |
NULL |
TRUE |
TRUE |
FALSE |
FALSE |
$x = array(); |
array |
TRUE |
FALSE |
TRUE |
FALSE |
$x = array('a', 'b'); |
array |
FALSE |
FALSE |
TRUE |
TRUE |
$x = false; |
boolean |
TRUE |
FALSE |
TRUE |
FALSE |
$x = true; |
boolean |
FALSE |
FALSE |
TRUE |
TRUE |
$x = 1; |
integer |
FALSE |
FALSE |
TRUE |
TRUE |
$x = 42; |
integer |
FALSE |
FALSE |
TRUE |
TRUE |
$x = 0; |
integer |
TRUE |
FALSE |
TRUE |
FALSE |
$x = -1; |
integer |
FALSE |
FALSE |
TRUE |
TRUE |
$x = "1"; |
string |
FALSE |
FALSE |
TRUE |
TRUE |
$x = "0"; |
string |
TRUE |
FALSE |
TRUE |
FALSE |
$x = "-1"; |
string |
FALSE |
FALSE |
TRUE |
TRUE |
$x = "php"; |
string |
FALSE |
FALSE |
TRUE |
TRUE |
$x = "true"; |
string |
FALSE |
FALSE |
TRUE |
TRUE |
$x = "false"; |
string |
FALSE |
FALSE |
TRUE |
TRUE |