Fluffy ElePHPant

Too much ?

Take a break and rest your eyes.

 

PHP Cheatsheets

PHP Variable Testing

Important notes on the comparisons and tests:

  1. There appear to be two null values at the start of the test. The first one is actually an unset variable, i.e. no longer in existence. The second is a variable which was set to null.
  2. Tests with Ctype and strcmp-type functions use the system default C locale. Results may vary for other locales.
  3. Some tests might seem a bit ‘silly’, for instance testing with === 'null'. The reason for adding these tests can be divided into two categories:
    1. Data received from databases and $_POST/$_GET/etc variables are always received as strings (unless a potentially used database abstraction layer changes this). So sometimes testing for a string value where a non-string variable type would be more logical, can actually make sense.
    2. Some are unfortunately regularly encountered in code and added here to illustrate why not to use them.
  4. BEWARE: some variable changing functions will not return a changed value, but will return whether the changing succeeded. You will find this indicated in the function header by the use of $copy (as the test will use a copy of the variable to not influence the other tests in the same table).

Notes on some variables:

Some of the test variables used, do not print the way they are set, either because they contain invisible characters or because they result in something else, so for your convenience, these are outlined here:

How the variable is defined:
i8 $x = 0xCC00F9; // Hexadecimal integer.
i9 $x = 052; // Octal integer.
ia $x = 0b0111001; // Binary integer (PHP5.4+).
ib $x = ‏௫‏; // Tamil digit five - entered as string as PHP itself cannot deal with it as an integer.
ic $x = ⁸₈; // Unicode superscript and subscript digit 8 - entered as a string as PHP itself cannot deal with these as integers.
f5 $x = acos(8); // = NAN
f6 $x = NAN; // = Not a number.
f7 $x = log(0); // = Infinite.
f8 $x = INF; // = Infinite.
f9 $x = 1.2345E8; // Exponent notation float.
fa $x = ⅕; // Unicode character representing 1/5 - entered as string as PHP itself cannot deal with it as a float.
sk $x = "123, \"str\"\r\n";
sn $x = "\f\t\r\n";
sp $x = "\x7f\t\r\n"

Legend / How to use the tables:

  • The error level for this test sheet has been set to E_ALL & ~E_STRICT. All errors are caught and referenced (with #links) in the tables with details of the error messages (if any) below each table. Similar error messages are grouped together for your convenience.
  • Some column labels have been shortened to avoid them taking undue space. These are indicated by a . If you mouse-over the column label you will see the full variable/test information.
  • In comparison tables, the left-top table header will indicate the comparison used and link to the relevant page in the PHP Manual.
  • In test tables, the left top table header indicates the type of tests. Both this header as well as most column headers link to their respective relevant PHP Manual pages.
  • A ‡ with a number next to a column header means there is a (linked) footnote for that entry at the bottom of the page.
  • When you mouse-over the table the row and column you are at are highlighted. To help you compare specific columns/rows, you can click on any cell to mark the column and row which the cell intersects for extra highlighting. Click again to remove this sticky highlight.

Legend to the color coding

NULL: null
Boolean: true / false
Integer: 123456789 / 0
Float: 12345.6789
String: ‘A string’
Array and Object: Indicated as such. Array keys, array values and object properties will be color coded according to the coding shown here.
Resources: Resource id #45
General typing gettype() empty() is_null() isset() (bool) if( $x ) {..} General typing
General typing gettype() empty() is_null() isset() (bool) if( $x ) {..} General typing
$x = null : ( = NULL )
‘NULL’ true true false false false $x = null : ( = NULL )
$x = null : ( = NULL )
‘NULL’ true true false false false $x = null : ( = NULL )
$x = bool : ( = false )
‘boolean’ true false true false false $x = bool : ( = false )
$x = bool : 1 ( = true )
‘boolean’ false false true true true $x = bool : 1 ( = true )
$x = int : 1
‘integer’ false false true true true $x = int : 1
$x = int : 0
‘integer’ true false true false false $x = int : 0
$x = int : -1
‘integer’ false false true true true $x = int : -1
$x = int : 42
‘integer’ false false true true true $x = int : 42
†i8$x = int : 13369593
‘integer’ false false true true true †i8$x = int : 13369593
†i9$x = int : 42
‘integer’ false false true true true †i9$x = int : 42
†ia$x = int : 57
‘integer’ false false true true true †ia$x = int : 57
$x = float : 1.3
‘double’ false false true true true $x = float : 1.3
$x = float : 0.005
‘double’ false false true true true $x = float : 0.005
$x = float : 0
‘double’ true false true false false $x = float : 0
$x = float : -1.3
‘double’ false false true true true $x = float : -1.3
†f5$x = float : NAN
‘double’ false false true true true †f5$x = float : NAN
†f6$x = float : NAN
‘double’ false false true true true †f6$x = float : NAN
†f7$x = float : -INF
‘double’ false false true true true †f7$x = float : -INF
†f8$x = float : INF
‘double’ false false true true true †f8$x = float : INF
†f9$x = float : 123450000
‘double’ false false true true true †f9$x = float : 123450000
$x = string[0] : ‘’
‘string’ true false true false false $x = string[0] : ‘’
$x = string[1] : ‘ ’
‘string’ false false true true true $x = string[1] : ‘ ’
$x = string[2] : ‘ 1’
‘string’ false false true true true $x = string[2] : ‘ 1’
$x = string[3] : ‘ 3 ’
‘string’ false false true true true $x = string[3] : ‘ 3 ’
$x = string[1] : ‘1’
‘string’ false false true true true $x = string[1] : ‘1’
$x = string[1] : ‘0’
‘string’ true false true false false $x = string[1] : ‘0’
$x = string[2] : ‘-1’
‘string’ false false true true true $x = string[2] : ‘-1’
$x = string[2] : ‘42’
‘string’ false false true true true $x = string[2] : ‘42’
$x = string[3] : ‘1.3’
‘string’ false false true true true $x = string[3] : ‘1.3’
$x = string[3] : ‘0.0’
‘string’ false false true true true $x = string[3] : ‘0.0’
$x = string[6] : ‘-1.305’
‘string’ false false true true true $x = string[6] : ‘-1.305’
$x = string[4] : ‘true’
‘string’ false false true true true $x = string[4] : ‘true’
$x = string[5] : ‘false’
‘string’ false false true true true $x = string[5] : ‘false’
$x = string[4] : ‘null’
‘string’ false false true true true $x = string[4] : ‘null’
$x = string[6] : ‘123str’
‘string’ false false true true true $x = string[6] : ‘123str’
$x = string[6] : ‘str123’
‘string’ false false true true true $x = string[6] : ‘str123’
$x = string[10] : ‘123, "str"’
‘string’ false false true true true $x = string[10] : ‘123, "str"’
$x = string[8] : ‘0xCC00F9’
‘string’ false false true true true $x = string[8] : ‘0xCC00F9’
$x = string[4] : ‘0123’
‘string’ false false true true true $x = string[4] : ‘0123’
$x = array()
‘array’ true false true false false $x = array()
$x = Array: (
    [1 (int)] => string[6] : ‘string’
)
‘array’ false false true true true $x = Array: (
    [1 (int)] => string[6] : ‘string’
)
$x = Array: (
    [0 (int)] => bool : ( = false )
    [1 (int)] => int : 1
    [2 (int)] => float : 1.3
    [3 (int)] => string[6] : ‘123str’
    [4 (int)] => string[6] : ‘str123’
    [5 (int)] => null : ( = NULL )
)
‘array’ false false true true true $x = Array: (
    [0 (int)] => bool : ( = false )
    [1 (int)] => int : 1
    [2 (int)] => float : 1.3
    [3 (int)] => string[6] : ‘123str’
    [4 (int)] => string[6] : ‘str123’
    [5 (int)] => null : ( = NULL )
)
$x = Object: (
    Class: stdClass (
    )
)
‘object’ false false true true true $x = Object: (
    Class: stdClass (
    )
)
$x = Object: (
    Class: TestObjectToString (
        property: test3 = string[11] : ‘some string’
        property: test1 = null : ( = NULL )
        property: test2 = bool : 1 ( = true )
        method: __toString
        method: print_it
    )
)
‘object’ false false true true true $x = Object: (
    Class: TestObjectToString (
        property: test3 = string[11] : ‘some string’
        property: test1 = null : ( = NULL )
        property: test2 = bool : 1 ( = true )
        method: __toString
        method: print_it
    )
)
$x = resource : Resource id #47 ( = RESOURCE )
‘resource’ false false true true true $x = resource : Resource id #47 ( = RESOURCE )
  1. Notice: Undefined index: notset
is_…() gettype() is_null() is_scalar() is_bool() is_int() is_float() is_string() is_array() is_object() is_resource() is_callable() is_numeric() is_…()
is_…() gettype() is_null() is_scalar() is_bool() is_int() is_float() is_string() is_array() is_object() is_resource() is_callable() is_numeric() is_…()
$x = null : ( = NULL )
‘NULL’ true false false false false false false false false false false $x = null : ( = NULL )
$x = null : ( = NULL )
‘NULL’ true false false false false false false false false false false $x = null : ( = NULL )
$x = bool : ( = false )
‘boolean’ false true true false false false false false false false false $x = bool : ( = false )
$x = bool : 1 ( = true )
‘boolean’ false true true false false false false false false false false $x = bool : 1 ( = true )
$x = int : 1
‘integer’ false true false true false false false false false false true $x = int : 1
$x = int : 0
‘integer’ false true false true false false false false false false true $x = int : 0
$x = int : -1
‘integer’ false true false true false false false false false false true $x = int : -1
$x = int : 42
‘integer’ false true false true false false false false false false true $x = int : 42
†i8$x = int : 13369593
‘integer’ false true false true false false false false false false true †i8$x = int : 13369593
†i9$x = int : 42
‘integer’ false true false true false false false false false false true †i9$x = int : 42
†ia$x = int : 57
‘integer’ false true false true false false false false false false true †ia$x = int : 57
$x = float : 1.3
‘double’ false true false false true false false false false false true $x = float : 1.3
$x = float : 0.005
‘double’ false true false false true false false false false false true $x = float : 0.005
$x = float : 0
‘double’ false true false false true false false false false false true $x = float : 0
$x = float : -1.3
‘double’ false true false false true false false false false false true $x = float : -1.3
†f5$x = float : NAN
‘double’ false true false false true false false false false false true †f5$x = float : NAN
†f6$x = float : NAN
‘double’ false true false false true false false false false false true †f6$x = float : NAN
†f7$x = float : -INF
‘double’ false true false false true false false false false false true †f7$x = float : -INF
†f8$x = float : INF
‘double’ false true false false true false false false false false true †f8$x = float : INF
†f9$x = float : 123450000
‘double’ false true false false true false false false false false true †f9$x = float : 123450000
$x = string[0] : ‘’
‘string’ false true false false false true false false false false false $x = string[0] : ‘’
$x = string[1] : ‘ ’
‘string’ false true false false false true false false false false false $x = string[1] : ‘ ’
$x = string[2] : ‘ 1’
‘string’ false true false false false true false false false false true $x = string[2] : ‘ 1’
$x = string[3] : ‘ 3 ’
‘string’ false true false false false true false false false false false $x = string[3] : ‘ 3 ’
$x = string[1] : ‘1’
‘string’ false true false false false true false false false false true $x = string[1] : ‘1’
$x = string[1] : ‘0’
‘string’ false true false false false true false false false false true $x = string[1] : ‘0’
$x = string[2] : ‘-1’
‘string’ false true false false false true false false false false true $x = string[2] : ‘-1’
$x = string[2] : ‘42’
‘string’ false true false false false true false false false false true $x = string[2] : ‘42’
$x = string[3] : ‘1.3’
‘string’ false true false false false true false false false false true $x = string[3] : ‘1.3’
$x = string[3] : ‘0.0’
‘string’ false true false false false true false false false false true $x = string[3] : ‘0.0’
$x = string[6] : ‘-1.305’
‘string’ false true false false false true false false false false true $x = string[6] : ‘-1.305’
$x = string[4] : ‘true’
‘string’ false true false false false true false false false false false $x = string[4] : ‘true’
$x = string[5] : ‘false’
‘string’ false true false false false true false false false false false $x = string[5] : ‘false’
$x = string[4] : ‘null’
‘string’ false true false false false true false false false false false $x = string[4] : ‘null’
$x = string[6] : ‘123str’
‘string’ false true false false false true false false false false false $x = string[6] : ‘123str’
$x = string[6] : ‘str123’
‘string’ false true false false false true false false false false false $x = string[6] : ‘str123’
$x = string[10] : ‘123, "str"’
‘string’ false true false false false true false false false false false $x = string[10] : ‘123, "str"’
$x = string[8] : ‘is_array’
‘string’ false true false false false true false false false true false $x = string[8] : ‘is_array’
$x = string[8] : ‘0xCC00F9’
‘string’ false true false false false true false false false false true $x = string[8] : ‘0xCC00F9’
$x = string[4] : ‘0123’
‘string’ false true false false false true false false false false true $x = string[4] : ‘0123’
$x = array()
‘array’ false false false false false false true false false false false $x = array()
$x = Array: (
    [1 (int)] => string[6] : ‘string’
)
‘array’ false false false false false false true false false false false $x = Array: (
    [1 (int)] => string[6] : ‘string’
)
$x = Array: (
    [0 (int)] => bool : ( = false )
    [1 (int)] => int : 1
    [2 (int)] => float : 1.3
    [3 (int)] => string[6] : ‘123str’
    [4 (int)] => string[6] : ‘str123’
    [5 (int)] => null : ( = NULL )
)
‘array’ false false false false false false true false false false false $x = Array: (
    [0 (int)] => bool : ( = false )
    [1 (int)] => int : 1
    [2 (int)] => float : 1.3
    [3 (int)] => string[6] : ‘123str’
    [4 (int)] => string[6] : ‘str123’
    [5 (int)] => null : ( = NULL )
)
$x = Object: (
    Class: stdClass (
    )
)
‘object’ false false false false false false false true false false false $x = Object: (
    Class: stdClass (
    )
)
$x = Object: (
    Class: TestObjectToString (
        property: test3 = string[11] : ‘some string’
        property: test1 = null : ( = NULL )
        property: test2 = bool : 1 ( = true )
        method: __toString
        method: print_it
    )
)
‘object’ false false false false false false false true false false false $x = Object: (
    Class: TestObjectToString (
        property: test3 = string[11] : ‘some string’
        property: test1 = null : ( = NULL )
        property: test2 = bool : 1 ( = true )
        method: __toString
        method: print_it
    )
)
$x = resource : Resource id #51 ( = RESOURCE )
‘resource’ false false false false false false false false true false false $x = resource : Resource id #51 ( = RESOURCE )
  1. Notice: Undefined index: notset
Null settype ( $copy, 'null' ) (unset) unset() CastToType::_null ( $x ) ‡1 isset() empty() is_null() == null === null == 'null' === 'null' Null
Null settype ( $copy, 'null' ) (unset) unset() CastToType::_null ( $x ) ‡1 isset() empty() is_null() == null === null == 'null' === 'null' Null
$x = null : ( = NULL )
null null null
#2 )
null false true true true true false false $x = null : ( = NULL )
$x = null : ( = NULL )
null null null
#2 )
null false true true true true false false $x = null : ( = NULL )
$x = bool : ( = false )
null null null
#2 )
null true true false true false false false $x = bool : ( = false )
$x = bool : 1 ( = true )
null null null
#2 )
null true false false false false true false $x = bool : 1 ( = true )
$x = int : 1
null null null
#2 )
null true false false false false false false $x = int : 1
$x = int : 0
null null null
#2 )
null true true false true false true false $x = int : 0
$x = int : -1
null null null
#2 )
null true false false false false false false $x = int : -1
$x = int : 42
null null null
#2 )
null true false false false false false false $x = int : 42
†i8$x = int : 13369593
null null null
#2 )
null true false false false false false false †i8$x = int : 13369593
†i9$x = int : 42
null null null
#2 )
null true false false false false false false †i9$x = int : 42
†ia$x = int : 57
null null null
#2 )
null true false false false false false false †ia$x = int : 57
$x = float : 1.3
null null null
#2 )
null true false false false false false false $x = float : 1.3
$x = float : 0.005
null null null
#2 )
null true false false false false false false $x = float : 0.005
$x = float : 0
null null null
#2 )
null true true false true false true false $x = float : 0
$x = float : -1.3
null null null
#2 )
null true false false false false false false $x = float : -1.3
†f5$x = float : NAN
null null null
#2 )
null true false false false false false false †f5$x = float : NAN
†f6$x = float : NAN
null null null
#2 )
null true false false false false false false †f6$x = float : NAN
†f7$x = float : -INF
null null null
#2 )
null true false false false false false false †f7$x = float : -INF
†f8$x = float : INF
null null null
#2 )
null true false false false false false false †f8$x = float : INF
†f9$x = float : 123450000
null null null
#2 )
null true false false false false false false †f9$x = float : 123450000
$x = string[0] : ‘’
null null null
#2 )
null true true false true false false false $x = string[0] : ‘’
$x = string[1] : ‘ ’
null null null
#2 )
null true false false false false false false $x = string[1] : ‘ ’
$x = string[2] : ‘ 1’
null null null
#2 )
null true false false false false false false $x = string[2] : ‘ 1’
$x = string[3] : ‘ 3 ’
null null null
#2 )
null true false false false false false false $x = string[3] : ‘ 3 ’
$x = string[1] : ‘1’
null null null
#2 )
null true false false false false false false $x = string[1] : ‘1’
$x = string[1] : ‘0’
null null null
#2 )
null true true false false false false false $x = string[1] : ‘0’
$x = string[2] : ‘-1’
null null null
#2 )
null true false false false false false false $x = string[2] : ‘-1’
$x = string[2] : ‘42’
null null null
#2 )
null true false false false false false false $x = string[2] : ‘42’
$x = string[3] : ‘1.3’
null null null
#2 )
null true false false false false false false $x = string[3] : ‘1.3’
$x = string[3] : ‘0.0’
null null null
#2 )
null true false false false false false false $x = string[3] : ‘0.0’
$x = string[6] : ‘-1.305’
null null null
#2 )
null true false false false false false false $x = string[6] : ‘-1.305’
$x = string[4] : ‘true’
null null null
#2 )
null true false false false false false false $x = string[4] : ‘true’
$x = string[5] : ‘false’
null null null
#2 )
null true false false false false false false $x = string[5] : ‘false’
$x = string[4] : ‘null’
null null null
#2 )
null true false false false false true true $x = string[4] : ‘null’
$x = string[6] : ‘123str’
null null null
#2 )
null true false false false false false false $x = string[6] : ‘123str’
$x = string[6] : ‘str123’
null null null
#2 )
null true false false false false false false $x = string[6] : ‘str123’
$x = string[10] : ‘123, "str"’
null null null
#2 )
null true false false false false false false $x = string[10] : ‘123, "str"’
$x = string[8] : ‘0xCC00F9’
null null null
#2 )
null true false false false false false false $x = string[8] : ‘0xCC00F9’
$x = string[4] : ‘0123’
null null null
#2 )
null true false false false false false false $x = string[4] : ‘0123’
$x = array()
null null null
#2 )
null true true false true false false false $x = array()
$x = Array: (
    [1 (int)] => string[6] : ‘string’
)
null null null
#2 )
null true false false false false false false $x = Array: (
    [1 (int)] => string[6] : ‘string’
)
$x = Array: (
    [0 (int)] => bool : ( = false )
    [1 (int)] => int : 1
    [2 (int)] => float : 1.3
    [3 (int)] => string[6] : ‘123str’
    [4 (int)] => string[6] : ‘str123’
    [5 (int)] => null : ( = NULL )
)
null null null
#2 )
null true false false false false false false $x = Array: (
    [0 (int)] => bool : ( = false )
    [1 (int)] => int : 1
    [2 (int)] => float : 1.3
    [3 (int)] => string[6] : ‘123str’
    [4 (int)] => string[6] : ‘str123’
    [5 (int)] => null : ( = NULL )
)
$x = Object: (
    Class: stdClass (
    )
)
null null null
#2 )
null true false false false false false false $x = Object: (
    Class: stdClass (
    )
)
$x = Object: (
    Class: TestObjectToString (
        property: test3 = string[11] : ‘some string’
        property: test1 = null : ( = NULL )
        property: test2 = bool : 1 ( = true )
        method: __toString
        method: print_it
    )
)
null null null
#2 )
null true false false false false false false $x = Object: (
    Class: TestObjectToString (
        property: test3 = string[11] : ‘some string’
        property: test1 = null : ( = NULL )
        property: test2 = bool : 1 ( = true )
        method: __toString
        method: print_it
    )
)
$x = resource : Resource id #55 ( = RESOURCE )
null null null
#2 )
null true false false false false false false $x = resource : Resource id #55 ( = RESOURCE )
  1. Notice: Undefined index: notset
  2. Notice: Undefined variable: x
‡ 1

Uses an external library

Boolean settype ( $copy, 'bool' ) (bool) filter_var (…) filter_var (…) ‡1 ‡2 CastToType::_bool ( $x, false, false ) ‡3 is_bool() == true === true == 1 == 'true' == false === false == 0 == 'false' if( $x ) {..} if( ! $x ) {..} Boolean
Boolean settype ( $copy, 'bool' ) (bool) filter_var (…) filter_var (…) ‡1 ‡2 CastToType::_bool ( $x, false, false ) ‡3 is_bool() == true === true == 1 == 'true' == false === false == 0 == 'false' if( $x ) {..} if( ! $x ) {..} Boolean
$x = null : ( = NULL )
false false false false null false false false false false true false true false false true $x = null : ( = NULL )
$x = null : ( = NULL )
false false false false null false false false false false true false true false false true $x = null : ( = NULL )
$x = bool : ( = false )
false false false false false true false false false false true true true false false true $x = bool : ( = false )
$x = bool : 1 ( = true )
true true true true true true true true true true false false false true true false $x = bool : 1 ( = true )
$x = int : 1
true true true true true false true false true false false false false false true false $x = int : 1
$x = int : 0
false false false false false false false false false true true false true true false true $x = int : 0
$x = int : -1
true true false null null false true false false false false false false false true false $x = int : -1
$x = int : 42
true true false null null false true false false false false false false false true false $x = int : 42
†i8$x = int : 13369593
true true false null null false true false false false false false false false true false †i8$x = int : 13369593
†i9$x = int : 42
true true false null null false true false false false false false false false true false †i9$x = int : 42
†ia$x = int : 57
true true false null null false true false false false false false false false true false †ia$x = int : 57
$x = float : 1.3
true true false null null false true false false false false false false false true false $x = float : 1.3
$x = float : 0.005
true true false null null false true false false false false false false false true false $x = float : 0.005
$x = float : 0
false false false false false false false false false true true false true true false true $x = float : 0
$x = float : -1.3
true true false null null false true false false false false false false false true false $x = float : -1.3
†f5$x = float : NAN
true true false null null false true false false false false false false false true false †f5$x = float : NAN
†f6$x = float : NAN
true true false null null false true false false false false false false false true false †f6$x = float : NAN
†f7$x = float : -INF
true true false null null false true false false false false false false false true false †f7$x = float : -INF
†f8$x = float : INF
true true false null null false true false false false false false false false true false †f8$x = float : INF
†f9$x = float : 123450000
true true false null null false true false false false false false false false true false †f9$x = float : 123450000
$x = string[0] : ‘’
false false false false null false false false false false true false true false false true $x = string[0] : ‘’
$x = string[1] : ‘ ’
true true false false null false true false false false false false true false true false $x = string[1] : ‘ ’
$x = string[2] : ‘ 1’
true true true true true false true false true false false false false false true false $x = string[2] : ‘ 1’
$x = string[3] : ‘ 3 ’
true true false null null false true false false false false false false false true false $x = string[3] : ‘ 3 ’
$x = string[1] : ‘1’
true true true true true false true false true false false false false false true false $x = string[1] : ‘1’
$x = string[1] : ‘0’
false false false false false false false false false false true false true false false true $x = string[1] : ‘0’
$x = string[2] : ‘-1’
true true false null null false true false false false false false false false true false $x = string[2] : ‘-1’
$x = string[2] : ‘42’
true true false null null false true false false false false false false false true false $x = string[2] : ‘42’
$x = string[3] : ‘1.3’
true true false null null false true false false false false false false false true false $x = string[3] : ‘1.3’
$x = string[3] : ‘0.0’
true true false null null false true false false false false false true false true false $x = string[3] : ‘0.0’
$x = string[6] : ‘-1.305’
true true false null null false true false false false false false false false true false $x = string[6] : ‘-1.305’
$x = string[4] : ‘true’
true true true true true false true false false true false false true false true false $x = string[4] : ‘true’
$x = string[5] : ‘false’
true true false false false false true false false false false false true true true false $x = string[5] : ‘false’
$x = string[4] : ‘null’
true true false null null false true false false false false false true false true false $x = string[4] : ‘null’
$x = string[6] : ‘123str’
true true false null null false true false false false false false false false true false $x = string[6] : ‘123str’
$x = string[6] : ‘str123’
true true false null null false true false false false false false true false true false $x = string[6] : ‘str123’
$x = string[10] : ‘123, "str"’
true true false null null false true false false false false false false false true false $x = string[10] : ‘123, "str"’
$x = string[2] : ‘on’
true true true true true false true false false false false false true false true false $x = string[2] : ‘on’
$x = string[3] : ‘off’
true true false false false false true false false false false false true false true false $x = string[3] : ‘off’
$x = string[3] : ‘yes’
true true true true true false true false false false false false true false true false $x = string[3] : ‘yes’
$x = string[2] : ‘no’
true true false false false false true false false false false false true false true false $x = string[2] : ‘no’
$x = string[8] : ‘0xCC00F9’
true true false null null false true false false false false false false false true false $x = string[8] : ‘0xCC00F9’
$x = string[4] : ‘0123’
true true false null null false true false false false false false false false true false $x = string[4] : ‘0123’
$x = array()
false false array()
array()
null false false false false false true false false false false true $x = array()
$x = Array: (
    [1 (int)] => string[6] : ‘string’
)
true true Array: (
  [1] => b false
)
Array: (
  [1] => null
)
Array: (
  [1] => null
)
false true false false false false false false false true false $x = Array: (
    [1 (int)] => string[6] : ‘string’
)
$x = Array: (
    [0 (int)] => bool : ( = false )
    [1 (int)] => int : 1
    [2 (int)] => float : 1.3
    [3 (int)] => string[6] : ‘123str’
    [4 (int)] => string[6] : ‘str123’
    [5 (int)] => null : ( = NULL )
)
true true Array: (
  [0] => b false
  [1] => b true
  [2] => b false
  [3] => b false
  [4] => b false
  [5] => b false
)
Array: (
  [0] => b false
  [1] => b true
  [2] => null
  [3] => null
  [4] => null
  [5] => b false
)
Array: (
  [0] => b false
  [1] => b true
  [2] => null
  [3] => null
  [4] => null
  [5] => null
)
false true false false false false false false false true false $x = Array: (
    [0 (int)] => bool : ( = false )
    [1 (int)] => int : 1
    [2 (int)] => float : 1.3
    [3 (int)] => string[6] : ‘123str’
    [4 (int)] => string[6] : ‘str123’
    [5 (int)] => null : ( = NULL )
)
$x = Object: (
    Class: stdClass (
    )
)
true true false false null false true false true
#2 )
false false false false
#2 )
false true false $x = Object: (
    Class: stdClass (
    )
)
$x = Object: (
    Class: TestObjectToString (
        property: test3 = string[11] : ‘some string’
        property: test1 = null : ( = NULL )
        property: test2 = bool : 1 ( = true )
        method: __toString
        method: print_it
    )
)
true true false null null false true false true
#2 )
false false false false
#2 )
false true false $x = Object: (
    Class: TestObjectToString (
        property: test3 = string[11] : ‘some string’
        property: test1 = null : ( = NULL )
        property: test2 = bool : 1 ( = true )
        method: __toString
        method: print_it
    )
)
$x = resource : Resource id #61 ( = RESOURCE )
true true false null null false true false false false false false false false true false $x = resource : Resource id #61 ( = RESOURCE )
  1. Notice: Undefined index: notset
  2. Notice: Object of class stdClass/TestObject/TestObjectToString could not be converted to int
‡ 1

Please note: On some PHP versions filter_var( $x, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE ) where $x = false will incorrectly return null.
Also: with the same parameters filter_var() will return false instead of null for most objects.

‡ 2

The code snippet is simplified for brevity. Please refer to the source of this file on GitHub for full details on how to use filter_var_array().

‡ 3

Uses an external library

Integers settype ( $copy, 'int' ) (int) intval() $x + 0 filter_var (…) filter_var (…) ‡1 CastToType::_int ( $x, false, false ) ‡2 abs() empty() is_int() is_numeric() ctype_digit() ‡3 preg_match (`^[0-9]+$`) preg_match (`^[0-9-]+$`) preg_match (`^[\p{N}-]+$`u) Integers
Integers settype ( $copy, 'int' ) (int) intval() $x + 0 filter_var (…) filter_var (…) ‡1 CastToType::_int ( $x, false, false ) ‡2 abs() empty() is_int() is_numeric() ctype_digit() ‡3 preg_match (`^[0-9]+$`) preg_match (`^[0-9-]+$`) preg_match (`^[\p{N}-]+$`u) Integers
$x = null : ( = NULL )
0 0 0 0 b false
null null 0
true false false false false false false $x = null : ( = NULL )
$x = null : ( = NULL )
0 0 0 0 b false
null null 0
true false false false false false false $x = null : ( = NULL )
$x = bool : ( = false )
0 0 0 0 b false
null null 0
true false false false false false false $x = bool : ( = false )
$x = bool : 1 ( = true )
1 1 1 1 1 1 null 1
false false false false true true true $x = bool : 1 ( = true )
$x = int : 1
1 1 1 1 1 1 1 1
false true true false true true true $x = int : 1
$x = int : 0
0 0 0 0 0 0 0 0
true true true false true true true $x = int : 0
$x = int : -1
-1 -1 -1 -1 -1 -1 -1 1
false true true false false true true $x = int : -1
$x = int : 42
42 42 42 42 42 42 42 42
false true true false true true true $x = int : 42
†i8$x = int : 13369593
13369593 13369593 13369593 13369593 13369593 13369593 13369593 13369593
false true true true true true true †i8$x = int : 13369593
†i9$x = int : 42
42 42 42 42 42 42 42 42
false true true false true true true †i9$x = int : 42
†ia$x = int : 57
57 57 57 57 57 57 57 57
false true true true true true true †ia$x = int : 57
†ib$x = string[3] : ‘௫’
0 0 0 0 b false
null null 0
false false false false false false true †ib$x = string[3] : ‘௫’
†ic$x = string[6] : ‘⁸₈’
0 0 0 0 b false
null null 0
false false false false false false true †ic$x = string[6] : ‘⁸₈’
$x = float : 1.3
1 1 1 1.3 b false
null null 1.3 false false true false false false false $x = float : 1.3
$x = float : 0.005
0 0 0 0.005 b false
null null 0.005 false false true false false false false $x = float : 0.005
$x = float : 0
0 0 0 0 0 0 0 0 true false true false true true true $x = float : 0
$x = float : -1.3
-1 -1 -1 -1.3 b false
null null 1.3 false false true false false false false $x = float : -1.3
†f5$x = float : NAN
-2147483648 -2147483648 -2147483648 NAN b false
null null NAN false false true false false false false †f5$x = float : NAN
†f6$x = float : NAN
-2147483648 -2147483648 -2147483648 NAN b false
null null NAN false false true false false false false †f6$x = float : NAN
†f7$x = float : -INF
0 0 0 -INF b false
null null INF false false true false false false false †f7$x = float : -INF
†f8$x = float : INF
0 0 0 INF b false
null null INF false false true false false false false †f8$x = float : INF
†f9$x = float : 123450000
123450000 123450000 123450000 123450000 123450000 123450000 123450000 123450000 false false true false true true true †f9$x = float : 123450000
$x = string[0] : ‘’
0 0 0 0 b false
null null 0
true false false false false false false $x = string[0] : ‘’
$x = string[1] : ‘ ’
0 0 0 0 b false
null null 0
false false false false false false false $x = string[1] : ‘ ’
$x = string[2] : ‘ 1’
1 1 1 1 1 1 1 1
false false true false false false false $x = string[2] : ‘ 1’
$x = string[3] : ‘ 3 ’
3 3 3 3 3 3 3 3
false false false false false false false $x = string[3] : ‘ 3 ’
$x = string[1] : ‘1’
1 1 1 1 1 1 1 1
false false true true true true true $x = string[1] : ‘1’
$x = string[1] : ‘0’
0 0 0 0 0 0 0 0
true false true true true true true $x = string[1] : ‘0’
$x = string[2] : ‘-1’
-1 -1 -1 -1 -1 -1 -1 1
false false true false false true true $x = string[2] : ‘-1’
$x = string[2] : ‘42’
42 42 42 42 42 42 42 42
false false true true true true true $x = string[2] : ‘42’
$x = string[3] : ‘1.3’
1 1 1 1.3 b false
null null 1.3 false false true false false false false $x = string[3] : ‘1.3’
$x = string[3] : ‘0.0’
0 0 0 0 b false
null null 0 false false true false false false false $x = string[3] : ‘0.0’
$x = string[6] : ‘-1.305’
-1 -1 -1 -1.305 b false
null null 1.305 false false true false false false false $x = string[6] : ‘-1.305’
$x = string[4] : ‘true’
0 0 0 0 b false
null null 0
false false false false false false false $x = string[4] : ‘true’
$x = string[5] : ‘false’
0 0 0 0 b false
null null 0
false false false false false false false $x = string[5] : ‘false’
$x = string[4] : ‘null’
0 0 0 0 b false
null null 0
false false false false false false false $x = string[4] : ‘null’
$x = string[6] : ‘123str’
123 123 123 123 b false
null null 123
false false false false false false false $x = string[6] : ‘123str’
$x = string[6] : ‘str123’
0 0 0 0 b false
null null 0
false false false false false false false $x = string[6] : ‘str123’
$x = string[10] : ‘123, "str"’
123 123 123 123 b false
null null 123
false false false false false false false $x = string[10] : ‘123, "str"’
$x = string[8] : ‘0xCC00F9’
0 0 0 13369593 b false
null null 13369593
false false true false false false false $x = string[8] : ‘0xCC00F9’
$x = string[4] : ‘0123’
123 123 123 123 b false
null 123 123
false false true true true true true $x = string[4] : ‘0123’
$x = array()
0 0 0
Fatal error ( #2 )
array()
array()
null b false
true false false false Error
#3 )
Error
#3 )
Error
#3 )
$x = array()
$x = Array: (
    [1 (int)] => string[6] : ‘string’
)
1 1 1
Fatal error ( #2 )
Array: (
  [1] => b false
)
Array: (
  [1] => null
)
Array: (
  [1] => null
)
b false
false false false false Error
#3 )
Error
#3 )
Error
#3 )
$x = Array: (
    [1 (int)] => string[6] : ‘string’
)
$x = Array: (
    [0 (int)] => bool : ( = false )
    [1 (int)] => int : 1
    [2 (int)] => float : 1.3
    [3 (int)] => string[6] : ‘123str’
    [4 (int)] => string[6] : ‘str123’
    [5 (int)] => null : ( = NULL )
)
1 1 1
Fatal error ( #2 )
Array: (
  [0] => b false
  [1] => 1
  [2] => b false
  [3] => b false
  [4] => b false
  [5] => b false
)
Array: (
  [0] => null
  [1] => 1
  [2] => null
  [3] => null
  [4] => null
  [5] => null
)
Array: (
  [0] => null
  [1] => 1
  [2] => null
  [3] => null
  [4] => null
  [5] => null
)
b false
false false false false Error
#3 )
Error
#3 )
Error
#3 )
$x = Array: (
    [0 (int)] => bool : ( = false )
    [1 (int)] => int : 1
    [2 (int)] => float : 1.3
    [3 (int)] => string[6] : ‘123str’
    [4 (int)] => string[6] : ‘str123’
    [5 (int)] => null : ( = NULL )
)
$x = Object: (
    Class: stdClass (
    )
)
1
#4 )
1
#4 )
1
#4 )
1
#4 )
b false
b false
null 1

#4 )
false false false false Error
#3 )
Error
#3 )
Error
#3 )
$x = Object: (
    Class: stdClass (
    )
)
$x = Object: (
    Class: TestObjectToString (
        property: test3 = string[11] : ‘some string’
        property: test1 = null : ( = NULL )
        property: test2 = bool : 1 ( = true )
        method: __toString
        method: print_it
    )
)
1
#4 )
1
#4 )
1
#4 )
1
#4 )
b false
null null 1

#4 )
false false false false false false false $x = Object: (
    Class: TestObjectToString (
        property: test3 = string[11] : ‘some string’
        property: test1 = null : ( = NULL )
        property: test2 = bool : 1 ( = true )
        method: __toString
        method: print_it
    )
)
$x = resource : Resource id #65 ( = RESOURCE )
65 65 65 65 b false
null null 65
false false false false Error
#3 )
Error
#3 )
Error
#3 )
$x = resource : Resource id #65 ( = RESOURCE )
  1. Notice: Undefined index: notset
  2. Fatal error: Unsupported operand types
  3. Warning: preg_match() expects parameter 2 to be string, array/object/resource given
  4. Notice: Object of class stdClass/TestObject/TestObjectToString could not be converted to int
‡ 1

The code snippet is simplified for brevity. Please refer to the source of this file on GitHub for full details on how to use filter_var_array().

‡ 2

Uses an external library

‡ 3

Important: Integers between -128 and 255 are interpreted as the ASCII value pointing to a character (negative values have 256 added in order to allow characters in the Extended ASCII range).
In any other case, integers are interpreted as a string containing the decimal digits of the integer.

Floats settype ( $copy, 'float' ) (float) floatval() $x + 0.0 filter_var (…) filter_var (…) ‡1 CastToType::_float ( $x, false, false ) ‡2 empty() is_float() is_numeric() ctype_digit() ‡3 preg_match (`^[0-9\.]+$`) preg_match (`^[0-9\.-]+$`) preg_match (`^[\p{N}\.-]+$`u) Floats
Floats settype ( $copy, 'float' ) (float) floatval() $x + 0.0 filter_var (…) filter_var (…) ‡1 CastToType::_float ( $x, false, false ) ‡2 empty() is_float() is_numeric() ctype_digit() ‡3 preg_match (`^[0-9\.]+$`) preg_match (`^[0-9\.-]+$`) preg_match (`^[\p{N}\.-]+$`u) Floats
$x = null : ( = NULL )
0 0 0 0 b false
null null true false false false false false false $x = null : ( = NULL )
$x = null : ( = NULL )
0 0 0 0 b false
null null true false false false false false false $x = null : ( = NULL )
$x = bool : ( = false )
0 0 0 0 b false
null null true false false false false false false $x = bool : ( = false )
$x = bool : 1 ( = true )
1 1 1 1 1 1 1 false false false false true true true $x = bool : 1 ( = true )
$x = int : 1
1 1 1 1 1 1 1 false false true false true true true $x = int : 1
$x = int : 0
0 0 0 0 0 0 0 true false true false true true true $x = int : 0
$x = int : -1
-1 -1 -1 -1 -1 -1 -1 false false true false false true true $x = int : -1
$x = int : 42
42 42 42 42 42 42 42 false false true false true true true $x = int : 42
†i8$x = int : 13369593
13369593 13369593 13369593 13369593 13369593 13369593 13369593 false false true true true true true †i8$x = int : 13369593
†i9$x = int : 42
42 42 42 42 42 42 42 false false true false true true true †i9$x = int : 42
†ia$x = int : 57
57 57 57 57 57 57 57 false false true true true true true †ia$x = int : 57
$x = float : 1.3
1.3 1.3 1.3 1.3 1.3 1.3 1.3 false true true false true true true $x = float : 1.3
$x = float : 0.005
0.005 0.005 0.005 0.005 0.005 0.005 0.005 false true true false true true true $x = float : 0.005
$x = float : 0
0 0 0 0 0 0 0 true true true false true true true $x = float : 0
$x = float : -1.3
-1.3 -1.3 -1.3 -1.3 -1.3 -1.3 -1.3 false true true false false true true $x = float : -1.3
†f5$x = float : NAN
NAN NAN NAN NAN b false
null NAN false true true false false false false †f5$x = float : NAN
†f6$x = float : NAN
NAN NAN NAN NAN b false
null NAN false true true false false false false †f6$x = float : NAN
†f7$x = float : -INF
-INF -INF -INF -INF b false
null -INF false true true false false false false †f7$x = float : -INF
†f8$x = float : INF
INF INF INF INF b false
null INF false true true false false false false †f8$x = float : INF
†f9$x = float : 123450000
123450000 123450000 123450000 123450000 123450000 123450000 123450000 false true true false true true true †f9$x = float : 123450000
†fa$x = string[3] : ‘⅕’
0 0 0 0 b false
null null false false false false false false true †fa$x = string[3] : ‘⅕’
$x = string[0] : ‘’
0 0 0 0 b false
null null true false false false false false false $x = string[0] : ‘’
$x = string[1] : ‘ ’
0 0 0 0 b false
null null false false false false false false false $x = string[1] : ‘ ’
$x = string[2] : ‘ 1’
1 1 1 1 1 1 1 false false true false false false false $x = string[2] : ‘ 1’
$x = string[3] : ‘ 3 ’
3 3 3 3 3 3 3 false false false false false false false $x = string[3] : ‘ 3 ’
$x = string[1] : ‘1’
1 1 1 1 1 1 1 false false true true true true true $x = string[1] : ‘1’
$x = string[1] : ‘0’
0 0 0 0 0 0 0 true false true true true true true $x = string[1] : ‘0’
$x = string[2] : ‘-1’
-1 -1 -1 -1 -1 -1 -1 false false true false false true true $x = string[2] : ‘-1’
$x = string[2] : ‘42’
42 42 42 42 42 42 42 false false true true true true true $x = string[2] : ‘42’
$x = string[3] : ‘1.3’
1.3 1.3 1.3 1.3 1.3 1.3 1.3 false false true false true true true $x = string[3] : ‘1.3’
$x = string[3] : ‘0.0’
0 0 0 0 0 0 0 false false true false true true true $x = string[3] : ‘0.0’
$x = string[6] : ‘-1.305’
-1.305 -1.305 -1.305 -1.305 -1.305 -1.305 -1.305 false false true false false true true $x = string[6] : ‘-1.305’
$x = string[4] : ‘true’
0 0 0 0 b false
null null false false false false false false false $x = string[4] : ‘true’
$x = string[5] : ‘false’
0 0 0 0 b false
null null false false false false false false false $x = string[5] : ‘false’
$x = string[4] : ‘null’
0 0 0 0 b false
null null false false false false false false false $x = string[4] : ‘null’
$x = string[6] : ‘123str’
123 123 123 123 b false
null null false false false false false false false $x = string[6] : ‘123str’
$x = string[6] : ‘str123’
0 0 0 0 b false
null null false false false false false false false $x = string[6] : ‘str123’
$x = string[10] : ‘123, "str"’
123 123 123 123 b false
null null false false false false false false false $x = string[10] : ‘123, "str"’
$x = string[8] : ‘0xCC00F9’
0 0 0 13369593 b false
null null false false true false false false false $x = string[8] : ‘0xCC00F9’
$x = string[4] : ‘0123’
123 123 123 123 123 123 123 false false true true true true true $x = string[4] : ‘0123’
$x = array()
0 0 0
Fatal error ( #2 )
array()
array()
null true false false false Error
#3 )
Error
#3 )
Error
#3 )
$x = array()
$x = Array: (
    [1 (int)] => string[6] : ‘string’
)
1 1 1
Fatal error ( #2 )
Array: (
  [1] => b false
)
Array: (
  [1] => null
)
Array: (
  [1] => null
)
false false false false Error
#3 )
Error
#3 )
Error
#3 )
$x = Array: (
    [1 (int)] => string[6] : ‘string’
)
$x = Array: (
    [0 (int)] => bool : ( = false )
    [1 (int)] => int : 1
    [2 (int)] => float : 1.3
    [3 (int)] => string[6] : ‘123str’
    [4 (int)] => string[6] : ‘str123’
    [5 (int)] => null : ( = NULL )
)
1 1 1
Fatal error ( #2 )
Array: (
  [0] => b false
  [1] => 1
  [2] => 1.3
  [3] => b false
  [4] => b false
  [5] => b false
)
Array: (
  [0] => null
  [1] => 1
  [2] => 1.3
  [3] => null
  [4] => null
  [5] => null
)
Array: (
  [0] => null
  [1] => 1
  [2] => 1.3
  [3] => null
  [4] => null
  [5] => null
)
false false false false Error
#3 )
Error
#3 )
Error
#3 )
$x = Array: (
    [0 (int)] => bool : ( = false )
    [1 (int)] => int : 1
    [2 (int)] => float : 1.3
    [3 (int)] => string[6] : ‘123str’
    [4 (int)] => string[6] : ‘str123’
    [5 (int)] => null : ( = NULL )
)
$x = Object: (
    Class: stdClass (
    )
)
1
#4 )
1
#4 )
1
#4 )
1
#5 )
b false
b false
null false false false false Error
#3 )
Error
#3 )
Error
#3 )
$x = Object: (
    Class: stdClass (
    )
)
$x = Object: (
    Class: TestObjectToString (
        property: test3 = string[11] : ‘some string’
        property: test1 = null : ( = NULL )
        property: test2 = bool : 1 ( = true )
        method: __toString
        method: print_it
    )
)
1
#4 )
1
#4 )
1
#4 )
1
#5 )
b false
null null false false false false false false false $x = Object: (
    Class: TestObjectToString (
        property: test3 = string[11] : ‘some string’
        property: test1 = null : ( = NULL )
        property: test2 = bool : 1 ( = true )
        method: __toString
        method: print_it
    )
)
$x = resource : Resource id #69 ( = RESOURCE )
69 69 69 69 b false
null null false false false false Error
#3 )
Error
#3 )
Error
#3 )
$x = resource : Resource id #69 ( = RESOURCE )
  1. Notice: Undefined index: notset
  2. Fatal error: Unsupported operand types
  3. Warning: preg_match() expects parameter 2 to be string, array/object/resource given
  4. Notice: Object of class stdClass/TestObject/TestObjectToString could not be converted to double
  5. Notice: Object of class stdClass/TestObject/TestObjectToString could not be converted to int
‡ 1

The code snippet is simplified for brevity. Please refer to the source of this file on GitHub for full details on how to use filter_var_array().

‡ 2

Uses an external library

‡ 3

Important: Integers between -128 and 255 are interpreted as the ASCII value pointing to a character (negative values have 256 added in order to allow characters in the Extended ASCII range).
In any other case, integers are interpreted as a string containing the decimal digits of the integer.

Numeric tests is_numeric() ctype_digit() ‡1 preg_match (`^[\p{N}-]+$`u) preg_match (`^[\p{N}\.-]+$`u) > 0 >= 0 == 0 === 0 != 0 !== 0 < 0 <= 0 is_nan() is_finite() is_infinite() floor() ceil() round() Numeric tests
Numeric tests is_numeric() ctype_digit() ‡1 preg_match (`^[\p{N}-]+$`u) preg_match (`^[\p{N}\.-]+$`u) > 0 >= 0 == 0 === 0 != 0 !== 0 < 0 <= 0 is_nan() is_finite() is_infinite() floor() ceil() round() Numeric tests
$x = null : ( = NULL )
false false false false false true true false false true false true false true false 0 0 0 $x = null : ( = NULL )
$x = null : ( = NULL )
false false false false false true true false false true false true false true false 0 0 0 $x = null : ( = NULL )
$x = bool : ( = false )
false false false false false true true false false true false true false true false 0 0 0 $x = bool : ( = false )
$x = bool : 1 ( = true )
false false true true true true false false true true false false false true false 1 1 1 $x = bool : 1 ( = true )
$x = int : 1
true false true true true true false false true true false false false true false 1 1 1 $x = int : 1
$x = int : 0
true false true true false true true true false false false true false true false 0 0 0 $x = int : 0
$x = int : -1
true false true true false false false false true true true true false true false -1 -1 -1 $x = int : -1
$x = int : 42
true false true true true true false false true true false false false true false 42 42 42 $x = int : 42
†i8$x = int : 13369593
true true true true true true false false true true false false false true false 13369593 13369593 13369593 †i8$x = int : 13369593
†i9$x = int : 42
true false true true true true false false true true false false false true false 42 42 42 †i9$x = int : 42
†ia$x = int : 57
true true true true true true false false true true false false false true false 57 57 57 †ia$x = int : 57
†ib$x = string[3] : ‘௫’
false false true true false true true false false true false true null
#2 )
null
#3 )
null
#4 )
0 0 0 †ib$x = string[3] : ‘௫’
†ic$x = string[6] : ‘⁸₈’
false false true true false true true false false true false true null
#2 )
null
#3 )
null
#4 )
0 0 0 †ic$x = string[6] : ‘⁸₈’
$x = float : 1.3
true false false true true true false false true true false false false true false 1 2 1 $x = float : 1.3
$x = float : 0.005
true false false true true true false false true true false false false true false 0 1 0 $x = float : 0.005
$x = float : 0
true false true true false true true false false true false true false true false 0 0 0 $x = float : 0
$x = float : -1.3
true false false true false false false false true true true true false true false -2 -1 -1 $x = float : -1.3
†f5$x = float : NAN
true false false false false false false false true true false false true false false NAN NAN NAN †f5$x = float : NAN
†f6$x = float : NAN
true false false false false false false false true true false false true false false NAN NAN NAN †f6$x = float : NAN
†f7$x = float : -INF
true false false false false false false false true true true true false false true -INF -INF -INF †f7$x = float : -INF
†f8$x = float : INF
true false false false true true false false true true false false false false true INF INF INF †f8$x = float : INF
†f9$x = float : 123450000
true false true true true true false false true true false false false true false 123450000 123450000 123450000 †f9$x = float : 123450000
†fa$x = string[3] : ‘⅕’
false false true true false true true false false true false true null
#2 )
null
#3 )
null
#4 )
0 0 0 †fa$x = string[3] : ‘⅕’
$x = string[0] : ‘’
false false false false false true true false false true false true null
#2 )
null
#3 )
null
#4 )
0 0 0 $x = string[0] : ‘’
$x = string[1] : ‘ ’
false false false false false true true false false true false true null
#2 )
null
#3 )
null
#4 )
0 0 0 $x = string[1] : ‘ ’
$x = string[2] : ‘ 1’
true false false false true true false false true true false false false true false 1 1 1 $x = string[2] : ‘ 1’
$x = string[3] : ‘ 3 ’
false false false false true true false false true true false false false
#5 )
true
#5 )
false
#5 )
3 3 3 $x = string[3] : ‘ 3 ’
$x = string[1] : ‘1’
true true true true true true false false true true false false false true false 1 1 1 $x = string[1] : ‘1’
$x = string[1] : ‘0’
true true true true false true true false false true false true false true false 0 0 0 $x = string[1] : ‘0’
$x = string[2] : ‘-1’
true false true true false false false false true true true true false true false -1 -1 -1 $x = string[2] : ‘-1’
$x = string[2] : ‘42’
true true true true true true false false true true false false false true false 42 42 42 $x = string[2] : ‘42’
$x = string[3] : ‘1.3’
true false false true true true false false true true false false false true false 1 2 1 $x = string[3] : ‘1.3’
$x = string[3] : ‘0.0’
true false false true false true true false false true false true false true false 0 0 0 $x = string[3] : ‘0.0’
$x = string[6] : ‘-1.305’
true false false true false false false false true true true true false true false -2 -1 -1 $x = string[6] : ‘-1.305’
$x = string[4] : ‘true’
false false false false false true true false false true false true null
#2 )
null
#3 )
null
#4 )
0 0 0 $x = string[4] : ‘true’
$x = string[5] : ‘false’
false false false false false true true false false true false true null
#2 )
null
#3 )
null
#4 )
0 0 0 $x = string[5] : ‘false’
$x = string[4] : ‘null’
false false false false false true true false false true false true null
#2 )
null
#3 )
null
#4 )
0 0 0 $x = string[4] : ‘null’
$x = string[6] : ‘123str’
false false false false true true false false true true false false false
#5 )
true
#5 )
false
#5 )
123 123 123 $x = string[6] : ‘123str’
$x = string[6] : ‘str123’
false false false false false true true false false true false true null
#2 )
null
#3 )
null
#4 )
0 0 0 $x = string[6] : ‘str123’
$x = string[10] : ‘123, "str"’
false false false false true true false false true true false false false
#5 )
true
#5 )
false
#5 )
123 123 123 $x = string[10] : ‘123, "str"’
$x = string[8] : ‘0xCC00F9’
true false false false true true false false true true false false false true false 13369593 13369593 13369593 $x = string[8] : ‘0xCC00F9’
$x = string[4] : ‘0123’
true true true true true true false false true true false false false true false 123 123 123 $x = string[4] : ‘0123’
$x = array()
false false Error
#6 )
Error
#6 )
true true false false true true false false null
#2 )
null
#3 )
null
#4 )
b false
b false
b false
$x = array()
$x = Array: (
    [1 (int)] => string[6] : ‘string’
)
false false Error
#6 )
Error
#6 )
true true false false true true false false null
#2 )
null
#3 )
null
#4 )
b false
b false
b false
$x = Array: (
    [1 (int)] => string[6] : ‘string’
)
$x = Array: (
    [0 (int)] => bool : ( = false )
    [1 (int)] => int : 1
    [2 (int)] => float : 1.3
    [3 (int)] => string[6] : ‘123str’
    [4 (int)] => string[6] : ‘str123’
    [5 (int)] => null : ( = NULL )
)
false false Error
#6 )
Error
#6 )
true true false false true true false false null
#2 )
null
#3 )
null
#4 )
b false
b false
b false
$x = Array: (
    [0 (int)] => bool : ( = false )
    [1 (int)] => int : 1
    [2 (int)] => float : 1.3
    [3 (int)] => string[6] : ‘123str’
    [4 (int)] => string[6] : ‘str123’
    [5 (int)] => null : ( = NULL )
)
$x = Object: (
    Class: stdClass (
    )
)
false false Error
#6 )
Error
#6 )
true
#7 )
true
#7 )
false
#7 )
false true
#7 )
true false
#7 )
false
#7 )
null
#2 )
null
#3 )
null
#4 )
1
#7 )
1
#7 )
1
#7 )
$x = Object: (
    Class: stdClass (
    )
)
$x = Object: (
    Class: TestObjectToString (
        property: test3 = string[11] : ‘some string’
        property: test1 = null : ( = NULL )
        property: test2 = bool : 1 ( = true )
        method: __toString
        method: print_it
    )
)
false false false false true
#7 )
true
#7 )
false
#7 )
false true
#7 )
true false
#7 )
false
#7 )
null
#2 )
null
#3 )
null
#4 )
1
#7 )
1
#7 )
1
#7 )
$x = Object: (
    Class: TestObjectToString (
        property: test3 = string[11] : ‘some string’
        property: test1 = null : ( = NULL )
        property: test2 = bool : 1 ( = true )
        method: __toString
        method: print_it
    )
)
$x = resource : Resource id #73 ( = RESOURCE )
false false Error
#6 )
Error
#6 )
true true false false true true false false null
#2 )
null
#3 )
null
#4 )
73 73 73 $x = resource : Resource id #73 ( = RESOURCE )
  1. Notice: Undefined index: notset
  2. Warning: is_nan() expects parameter 1 to be double, string/array/object/resource given
  3. Warning: is_finite() expects parameter 1 to be double, string/array/object/resource given
  4. Warning: is_infinite() expects parameter 1 to be double, string/array/object/resource given
  5. Notice: A non well formed numeric value encountered
  6. Warning: preg_match() expects parameter 2 to be string, array/object/resource given
  7. Notice: Object of class stdClass/TestObject/TestObjectToString could not be converted to int
‡ 1

Important: Integers between -128 and 255 are interpreted as the ASCII value pointing to a character (negative values have 256 added in order to allow characters in the Extended ASCII range).
In any other case, integers are interpreted as a string containing the decimal digits of the integer.

String casting settype ( $copy, 'string' ) ‡1 ‡2 (string) strval() $x . '' filter_var (…) filter_var (…) ‡3 CastToType::_string ( $x, false, false ) ‡4 String casting
String casting settype ( $copy, 'string' ) ‡1 ‡2 (string) strval() $x . '' filter_var (…) filter_var (…) ‡3 CastToType::_string ( $x, false, false ) ‡4 String casting
$x = null : ( = NULL )
‘’ ‘’ ‘’ ‘ ’ ‘’ ‘’ null $x = null : ( = NULL )
$x = null : ( = NULL )
‘’ ‘’ ‘’ ‘ ’ ‘’ ‘’ null $x = null : ( = NULL )
$x = bool : ( = false )
‘’ ‘’ ‘’ ‘ ’ ‘’ ‘’ null $x = bool : ( = false )
$x = bool : 1 ( = true )
‘1’ ‘1’ ‘1’ ‘1 ’ ‘1’ ‘1’ null $x = bool : 1 ( = true )
$x = int : 1
‘1’ ‘1’ ‘1’ ‘1 ’ ‘1’ ‘1’ ‘1’ $x = int : 1
$x = int : 0
‘0’ ‘0’ ‘0’ ‘0 ’ ‘0’ ‘0’ ‘0’ $x = int : 0
$x = int : -1
‘-1’ ‘-1’ ‘-1’ ‘-1 ’ ‘-1’ ‘-1’ ‘-1’ $x = int : -1
$x = int : 42
‘42’ ‘42’ ‘42’ ‘42 ’ ‘42’ ‘42’ ‘42’ $x = int : 42
†i8$x = int : 13369593
‘13369593’ ‘13369593’ ‘13369593’ ‘13369593 ’ ‘13369593’ ‘13369593’ ‘13369593’ †i8$x = int : 13369593
†i9$x = int : 42
‘42’ ‘42’ ‘42’ ‘42 ’ ‘42’ ‘42’ ‘42’ †i9$x = int : 42
†ia$x = int : 57
‘57’ ‘57’ ‘57’ ‘57 ’ ‘57’ ‘57’ ‘57’ †ia$x = int : 57
$x = float : 1.3
‘1.3’ ‘1.3’ ‘1.3’ ‘1.3 ’ ‘1.3’ ‘1.3’ ‘1.3’ $x = float : 1.3
$x = float : 0.005
‘0.005’ ‘0.005’ ‘0.005’ ‘0.005 ’ ‘0.005’ ‘0.005’ ‘0.005’ $x = float : 0.005
$x = float : 0
‘0’ ‘0’ ‘0’ ‘0 ’ ‘0’ ‘0’ ‘0’ $x = float : 0
$x = float : -1.3
‘-1.3’ ‘-1.3’ ‘-1.3’ ‘-1.3 ’ ‘-1.3’ ‘-1.3’ ‘-1.3’ $x = float : -1.3
†f5$x = float : NAN
‘NAN’ ‘NAN’ ‘NAN’ ‘NAN ’ ‘NAN’ ‘NAN’ ‘NAN’ †f5$x = float : NAN
†f6$x = float : NAN
‘NAN’ ‘NAN’ ‘NAN’ ‘NAN ’ ‘NAN’ ‘NAN’ ‘NAN’ †f6$x = float : NAN
†f7$x = float : -INF
‘-INF’ ‘-INF’ ‘-INF’ ‘-INF ’ ‘-INF’ ‘-INF’ ‘-INF’ †f7$x = float : -INF
†f8$x = float : INF
‘INF’ ‘INF’ ‘INF’ ‘INF ’ ‘INF’ ‘INF’ ‘INF’ †f8$x = float : INF
†f9$x = float : 123450000
‘123450000’ ‘123450000’ ‘123450000’ ‘123450000 ’ ‘123450000’ ‘123450000’ ‘123450000’ †f9$x = float : 123450000
$x = string[0] : ‘’
‘’ ‘’ ‘’ ‘ ’ ‘’ ‘’ null $x = string[0] : ‘’
$x = string[1] : ‘ ’
‘ ’ ‘ ’ ‘ ’ ‘  ’ ‘ ’ ‘ ’ ‘ ’ $x = string[1] : ‘ ’
$x = string[2] : ‘ 1’
‘ 1’ ‘ 1’ ‘ 1’ ‘ 1 ’ ‘ 1’ ‘ 1’ ‘ 1’ $x = string[2] : ‘ 1’
$x = string[3] : ‘ 3 ’
‘ 3 ’ ‘ 3 ’ ‘ 3 ’ ‘ 3  ’ ‘ 3 ’ ‘ 3 ’ ‘ 3 ’ $x = string[3] : ‘ 3 ’
$x = string[1] : ‘1’
‘1’ ‘1’ ‘1’ ‘1 ’ ‘1’ ‘1’ ‘1’ $x = string[1] : ‘1’
$x = string[1] : ‘0’
‘0’ ‘0’ ‘0’ ‘0 ’ ‘0’ ‘0’ ‘0’ $x = string[1] : ‘0’
$x = string[2] : ‘-1’
‘-1’ ‘-1’ ‘-1’ ‘-1 ’ ‘-1’ ‘-1’ ‘-1’ $x = string[2] : ‘-1’
$x = string[2] : ‘42’
‘42’ ‘42’ ‘42’ ‘42 ’ ‘42’ ‘42’ ‘42’ $x = string[2] : ‘42’
$x = string[3] : ‘1.3’
‘1.3’ ‘1.3’ ‘1.3’ ‘1.3 ’ ‘1.3’ ‘1.3’ ‘1.3’ $x = string[3] : ‘1.3’
$x = string[3] : ‘0.0’
‘0.0’ ‘0.0’ ‘0.0’ ‘0.0 ’ ‘0.0’ ‘0.0’ ‘0.0’ $x = string[3] : ‘0.0’
$x = string[6] : ‘-1.305’
‘-1.305’ ‘-1.305’ ‘-1.305’ ‘-1.305 ’ ‘-1.305’ ‘-1.305’ ‘-1.305’ $x = string[6] : ‘-1.305’
$x = string[4] : ‘true’
‘true’ ‘true’ ‘true’ ‘true ’ ‘true’ ‘true’ ‘true’ $x = string[4] : ‘true’
$x = string[5] : ‘false’
‘false’ ‘false’ ‘false’ ‘false ’ ‘false’ ‘false’ ‘false’ $x = string[5] : ‘false’
$x = string[4] : ‘null’
‘null’ ‘null’ ‘null’ ‘null ’ ‘null’ ‘null’ ‘null’ $x = string[4] : ‘null’
$x = string[6] : ‘123str’
‘123str’ ‘123str’ ‘123str’ ‘123str ’ ‘123str’ ‘123str’ ‘123str’ $x = string[6] : ‘123str’
$x = string[6] : ‘str123’
‘str123’ ‘str123’ ‘str123’ ‘str123 ’ ‘str123’ ‘str123’ ‘str123’ $x = string[6] : ‘str123’
$x = string[10] : ‘123, "str"’
‘123, "str"’ ‘123, "str"’ ‘123, "str"’ ‘123, "str" ’ ‘123, "str"’ ‘123, "str"’ ‘123, "str"’ $x = string[10] : ‘123, "str"’
$x = string[8] : ‘0xCC00F9’
‘0xCC00F9’ ‘0xCC00F9’ ‘0xCC00F9’ ‘0xCC00F9 ’ ‘0xCC00F9’ ‘0xCC00F9’ ‘0xCC00F9’ $x = string[8] : ‘0xCC00F9’
$x = string[4] : ‘0123’
‘0123’ ‘0123’ ‘0123’ ‘0123 ’ ‘0123’ ‘0123’ ‘0123’ $x = string[4] : ‘0123’
$x = array()
‘Array’
#2 )
‘Array’
#2 )
‘Array’
#2 )
‘Array ’
#2 )
array()
array()
null $x = array()
$x = Array: (
    [1 (int)] => string[6] : ‘string’
)
‘Array’
#2 )
‘Array’
#2 )
‘Array’
#2 )
‘Array ’
#2 )
Array: (
  [1] => ‘string’
)
Array: (
  [1] => ‘string’
)
Array: (
  [1] => ‘string’
)
$x = Array: (
    [1 (int)] => string[6] : ‘string’
)
$x = Array: (
    [0 (int)] => bool : ( = false )
    [1 (int)] => int : 1
    [2 (int)] => float : 1.3
    [3 (int)] => string[6] : ‘123str’
    [4 (int)] => string[6] : ‘str123’
    [5 (int)] => null : ( = NULL )
)
‘Array’
#2 )
‘Array’
#2 )
‘Array’
#2 )
‘Array ’
#2 )
Array: (
  [0] => ‘’
  [1] => ‘1’
  [2] => ‘1.3’
  [3] => ‘123str’
  [4] => ‘str123’
  [5] => ‘’
)
Array: (
  [0] => ‘’
  [1] => ‘1’
  [2] => ‘1.3’
  [3] => ‘123str’
  [4] => ‘str123’
  [5] => ‘’
)
Array: (
  [0] => null
  [1] => ‘1’
  [2] => ‘1.3’
  [3] => ‘123str’
  [4] => ‘str123’
  [5] => null
)
$x = Array: (
    [0 (int)] => bool : ( = false )
    [1 (int)] => int : 1
    [2 (int)] => float : 1.3
    [3 (int)] => string[6] : ‘123str’
    [4 (int)] => string[6] : ‘str123’
    [5 (int)] => null : ( = NULL )
)
$x = Object: (
    Class: stdClass (
    )
)
‘Object’
(Catchable) Fatal error ( #3 )
#4 )
‘’
(Catchable) Fatal error ( #3 )
‘’
(Catchable) Fatal error ( #3 )
‘ ’
(Catchable) Fatal error ( #3 )
b false
b false
null $x = Object: (
    Class: stdClass (
    )
)
$x = Object: (
    Class: TestObjectToString (
        property: test3 = string[11] : ‘some string’
        property: test1 = null : ( = NULL )
        property: test2 = bool : 1 ( = true )
        method: __toString
        method: print_it
    )
)
‘some string’ ‘some string’ ‘some string’ ‘some string ’ ‘some string’ ‘some string’ ‘some string’ $x = Object: (
    Class: TestObjectToString (
        property: test3 = string[11] : ‘some string’
        property: test1 = null : ( = NULL )
        property: test2 = bool : 1 ( = true )
        method: __toString
        method: print_it
    )
)
$x = resource : Resource id #77 ( = RESOURCE )
‘Resource id #77’ ‘Resource id #77’ ‘Resource id #77’ ‘Resource id #77 ’ ‘Resource id #77’ ‘Resource id #77’ null $x = resource : Resource id #77 ( = RESOURCE )
  1. Notice: Undefined index: notset
  2. Notice: Array to string conversion
  3. (Catchable) Fatal error: Object of class stdClass/TestObject/TestObjectToString could not be converted to string
  4. Notice: Object of class stdClass/TestObject/TestObjectToString to string conversion
‡ 1

Depending on your error handling settings/exception catching and your PHP version, using settype( $copy, 'string' ) on an object which does not have a __toString() method will result either in the string Object or will return a (catchable) fatal error.

‡ 2

Before PHP < 5.2.0, the __toString() method was only available to echo/print statements, so casting to string would still result in Object, even when the object contained a __toString() method.

‡ 3

The code snippet is simplified for brevity. Please refer to the source of this file on GitHub for full details on how to use filter_var_array().

‡ 4

Uses an external library

String tests is_string() empty() == '' === '' ctype_alpha() ‡1 preg_match (`^[A-Za-z]+$`) preg_match (`^\p{L}+$`u) ctype_alnum() ‡1 preg_match (`^[A-Za-z0-9]+$`) preg_match (`^\w+$`) preg_match (`^\w+$`u) ‡2 preg_match (`^[\p{L}\p{N}]+$`u) strlen() count_chars (…) mb_strlen() $x{2} trim() String tests
String tests is_string() empty() == '' === '' ctype_alpha() ‡1 preg_match (`^[A-Za-z]+$`) preg_match (`^\p{L}+$`u) ctype_alnum() ‡1 preg_match (`^[A-Za-z0-9]+$`) preg_match (`^\w+$`) preg_match (`^\w+$`u) ‡2 preg_match (`^[\p{L}\p{N}]+$`u) strlen() count_chars (…) mb_strlen() $x{2} trim() String tests
$x = null : ( = NULL )
false true true false false false false false false false false false 0 0
0 null ‘’
$x = null : ( = NULL )
$x = null : ( = NULL )
false true true false false false false false false false false false 0 0
0 null ‘’
$x = null : ( = NULL )
$x = bool : ( = false )
false true true false false false false false false false false false 0 0
0 null ‘’
$x = bool : ( = false )
$x = bool : 1 ( = true )
false false false false false false false false true true true true 1 1
1 null ‘1’
$x = bool : 1 ( = true )
$x = int : 1
false false false false false false false false true true true true 1 1
1 null ‘1’
$x = int : 1
$x = int : 0
false true true false false false false false true true true true 1 1
1 null ‘0’
$x = int : 0
$x = int : -1
false false false false false false false false false false false false 2 2
2 null ‘-1’
$x = int : -1
$x = int : 42
false false false false false false false false true true true true 2 2
2 null ‘42’
$x = int : 42
†i8$x = int : 13369593
false false false false false false false true true true true true 8 8
8 null ‘13369593’
†i8$x = int : 13369593
†i9$x = int : 42
false false false false false false false false true true true true 2 2
2 null ‘42’
†i9$x = int : 42
†ia$x = int : 57
false false false false false false false true true true true true 2 2
2 null ‘57’
†ia$x = int : 57
$x = float : 1.3
false false false false false false false false false false false false 3 3
3 null ‘1.3’
$x = float : 1.3
$x = float : 0.005
false false false false false false false false false false false false 5 5
5 null ‘0.005’
$x = float : 0.005
$x = float : 0
false true true false false false false false true true true true 1 1
1 null ‘0’
$x = float : 0
$x = float : -1.3
false false false false false false false false false false false false 4 4
4 null ‘-1.3’
$x = float : -1.3
†f5$x = float : NAN
false false false false false true true false true true true true 3 3
3 null ‘NAN’
†f5$x = float : NAN
†f6$x = float : NAN
false false false false false true true false true true true true 3 3
3 null ‘NAN’
†f6$x = float : NAN
†f7$x = float : -INF
false false false false false false false false false false false false 4 4
4 null ‘-INF’
†f7$x = float : -INF
†f8$x = float : INF
false false false false false true true false true true true true 3 3
3 null ‘INF’
†f8$x = float : INF
†f9$x = float : 123450000
false false false false false false false false true true true true 9 9
9 null ‘123450000’
†f9$x = float : 123450000
$x = string[0] : ‘’
true true true true false false false false false false false false 0 0
0 ‘’

#2 )
‘’
$x = string[0] : ‘’
$x = string[1] : ‘ ’
true false false false false false false false false false false false 1 1
1 ‘’

#2 )
‘’
$x = string[1] : ‘ ’
$x = string[2] : ‘ 1’
true false false false false false false false false false false false 2 2
2 ‘’

#2 )
‘1’
$x = string[2] : ‘ 1’
$x = string[3] : ‘ 3 ’
true false false false false false false false false false false false 3 3
3 ‘ ’
‘3’
$x = string[3] : ‘ 3 ’
$x = string[1] : ‘1’
true false false false false false false true true true true true 1 1
1 ‘’

#2 )
‘1’
$x = string[1] : ‘1’
$x = string[1] : ‘0’
true true false false false false false true true true true true 1 1
1 ‘’

#2 )
‘0’
$x = string[1] : ‘0’
$x = string[2] : ‘-1’
true false false false false false false false false false false false 2 2
2 ‘’

#2 )
‘-1’
$x = string[2] : ‘-1’
$x = string[2] : ‘42’
true false false false false false false true true true true true 2 2
2 ‘’

#2 )
‘42’
$x = string[2] : ‘42’
$x = string[3] : ‘1.3’
true false false false false false false false false false false false 3 3
3 ‘3’
‘1.3’
$x = string[3] : ‘1.3’
$x = string[3] : ‘0.0’
true false false false false false false false false false false false 3 3
3 ‘0’
‘0.0’
$x = string[3] : ‘0.0’
$x = string[6] : ‘-1.305’
true false false false false false false false false false false false 6 6
6 ‘.’
‘-1.305’
$x = string[6] : ‘-1.305’
$x = string[4] : ‘true’
true false false false true true true true true true true true 4 4
4 ‘u’
‘true’
$x = string[4] : ‘true’
$x = string[5] : ‘false’
true false false false true true true true true true true true 5 5
5 ‘l’
‘false’
$x = string[5] : ‘false’
$x = string[4] : ‘null’
true false false false true true true true true true true true 4 4
4 ‘l’
‘null’
$x = string[4] : ‘null’
$x = string[6] : ‘123str’
true false false false false false false true true true true true 6 6
6 ‘3’
‘123str’
$x = string[6] : ‘123str’
$x = string[6] : ‘str123’
true false false false false false false true true true true true 6 6
6 ‘r’
‘str123’
$x = string[6] : ‘str123’
$x = string[10] : ‘123, "str"’
true false false false false false false false false false false false 10 10
10 ‘3’
‘123, "str"’
$x = string[10] : ‘123, "str"’
$x = string[8] : ‘0xCC00F9’
true false false false false false false true true true true true 8 8
8 ‘C’
‘0xCC00F9’
$x = string[8] : ‘0xCC00F9’
$x = string[4] : ‘0123’
true false false false false false false true true true true true 4 4
4 ‘2’
‘0123’
$x = string[4] : ‘0123’
$x = string[27] : ‘Iñtërnâtiônàlizætiøn’
true false false false false false true false false false true true 27 27
20 ‘’
‘Iñtërnâtiônàlizætiøn’
$x = string[27] : ‘Iñtërnâtiônàlizætiøn’
$x = array()
false true false false false Error
#3 )
Error
#3 )
false Error
#3 )
Error
#3 )
Error
#3 )
Error
#3 )
null
#4 )
null
#5 )
#6 )
false
#7 )
null
#8 )
null
#9 )
$x = array()
$x = Array: (
    [1 (int)] => string[6] : ‘string’
)
false false false false false Error
#3 )
Error
#3 )
false Error
#3 )
Error
#3 )
Error
#3 )
Error
#3 )
null
#4 )
null
#5 )
#6 )
false
#7 )
null
#8 )
null
#9 )
$x = Array: (
    [1 (int)] => string[6] : ‘string’
)
$x = Array: (
    [0 (int)] => bool : ( = false )
    [1 (int)] => int : 1
    [2 (int)] => float : 1.3
    [3 (int)] => string[6] : ‘123str’
    [4 (int)] => string[6] : ‘str123’
    [5 (int)] => null : ( = NULL )
)
false false false false false Error
#3 )
Error
#3 )
false Error
#3 )
Error
#3 )
Error
#3 )
Error
#3 )
null
#4 )
null
#5 )
#6 )
false
#7 )
1.3
null
#9 )
$x = Array: (
    [0 (int)] => bool : ( = false )
    [1 (int)] => int : 1
    [2 (int)] => float : 1.3
    [3 (int)] => string[6] : ‘123str’
    [4 (int)] => string[6] : ‘str123’
    [5 (int)] => null : ( = NULL )
)
$x = Object: (
    Class: stdClass (
    )
)
false false false false false Error
#3 )
Error
#3 )
false Error
#3 )
Error
#3 )
Error
#3 )
Error
#3 )
null
#4 )
null
#5 )
#6 )
false
#7 )

Fatal error ( #10 )
null
#9 )
$x = Object: (
    Class: stdClass (
    )
)
$x = Object: (
    Class: TestObjectToString (
        property: test3 = string[11] : ‘some string’
        property: test1 = null : ( = NULL )
        property: test2 = bool : 1 ( = true )
        method: __toString
        method: print_it
    )
)
false false false false false false false false false false false false 11 11
11
Fatal error ( #10 )
‘some string’
$x = Object: (
    Class: TestObjectToString (
        property: test3 = string[11] : ‘some string’
        property: test1 = null : ( = NULL )
        property: test2 = bool : 1 ( = true )
        method: __toString
        method: print_it
    )
)
$x = resource : Resource id #81 ( = RESOURCE )
false false false false false Error
#3 )
Error
#3 )
false Error
#3 )
Error
#3 )
Error
#3 )
Error
#3 )
null
#4 )
null
#5 )
#6 )
false
#7 )
null null
#9 )
$x = resource : Resource id #81 ( = RESOURCE )
  1. Notice: Undefined index: notset
  2. Notice: Uninitialized string offset: 2
  3. Warning: preg_match() expects parameter 2 to be string, array/object/resource given
  4. Warning: strlen() expects parameter 1 to be string, array/object/resource given
  5. Warning: count_chars() expects parameter 1 to be string, array/object/resource given
  6. Warning: array_sum() expects parameter 1 to be array, null given
  7. Warning: mb_strlen() expects parameter 1 to be string, array/object/resource given
  8. Notice: Undefined offset: 2
  9. Warning: trim() expects parameter 1 to be string, array/object/resource given
  10. Fatal error: Cannot use object of type stdClass/TestObject/TestObjectToString as array
‡ 1

Important: Integers between -128 and 255 are interpreted as the ASCII value pointing to a character (negative values have 256 added in order to allow characters in the Extended ASCII range).
In any other case, integers are interpreted as a string containing the decimal digits of the integer.

‡ 2

What \w matches is locale dependent. The locale for these cheatsheets are set to C. Results with other locales will vary.

Array casting settype ( $copy, 'array' ) (array) CastToType::_array ( $x, false ) ‡1 Array casting
Array casting settype ( $copy, 'array' ) (array) CastToType::_array ( $x, false ) ‡1 Array casting
$x = null : ( = NULL )
array()
array()
null $x = null : ( = NULL )
$x = null : ( = NULL )
array()
array()
null $x = null : ( = NULL )
$x = bool : ( = false )
Array: (
  [0] => b false
)
Array: (
  [0] => b false
)
Array: (
  [0] => b false
)
$x = bool : ( = false )
$x = bool : 1 ( = true )
Array: (
  [0] => b true
)
Array: (
  [0] => b true
)
Array: (
  [0] => b true
)
$x = bool : 1 ( = true )
$x = int : 1
Array: (
  [0] => 1
)
Array: (
  [0] => 1
)
Array: (
  [0] => 1
)
$x = int : 1
$x = int : 0
Array: (
  [0] => 0
)
Array: (
  [0] => 0
)
Array: (
  [0] => 0
)
$x = int : 0
$x = int : -1
Array: (
  [0] => -1
)
Array: (
  [0] => -1
)
Array: (
  [0] => -1
)
$x = int : -1
$x = int : 42
Array: (
  [0] => 42
)
Array: (
  [0] => 42
)
Array: (
  [0] => 42
)
$x = int : 42
†i8$x = int : 13369593
Array: (
  [0] => 13369593
)
Array: (
  [0] => 13369593
)
Array: (
  [0] => 13369593
)
†i8$x = int : 13369593
†i9$x = int : 42
Array: (
  [0] => 42
)
Array: (
  [0] => 42
)
Array: (
  [0] => 42
)
†i9$x = int : 42
†ia$x = int : 57
Array: (
  [0] => 57
)
Array: (
  [0] => 57
)
Array: (
  [0] => 57
)
†ia$x = int : 57
$x = float : 1.3
Array: (
  [0] => 1.3
)
Array: (
  [0] => 1.3
)
Array: (
  [0] => 1.3
)
$x = float : 1.3
$x = float : 0.005
Array: (
  [0] => 0.005
)
Array: (
  [0] => 0.005
)
Array: (
  [0] => 0.005
)
$x = float : 0.005
$x = float : 0
Array: (
  [0] => 0
)
Array: (
  [0] => 0
)
Array: (
  [0] => 0
)
$x = float : 0
$x = float : -1.3
Array: (
  [0] => -1.3
)
Array: (
  [0] => -1.3
)
Array: (
  [0] => -1.3
)
$x = float : -1.3
†f5$x = float : NAN
Array: (
  [0] => NAN
)
Array: (
  [0] => NAN
)
Array: (
  [0] => NAN
)
†f5$x = float : NAN
†f6$x = float : NAN
Array: (
  [0] => NAN
)
Array: (
  [0] => NAN
)
Array: (
  [0] => NAN
)
†f6$x = float : NAN
†f7$x = float : -INF
Array: (
  [0] => -INF
)
Array: (
  [0] => -INF
)
Array: (
  [0] => -INF
)
†f7$x = float : -INF
†f8$x = float : INF
Array: (
  [0] => INF
)
Array: (
  [0] => INF
)
Array: (
  [0] => INF
)
†f8$x = float : INF
†f9$x = float : 123450000
Array: (
  [0] => 123450000
)
Array: (
  [0] => 123450000
)
Array: (
  [0] => 123450000
)
†f9$x = float : 123450000
$x = string[0] : ‘’
Array: (
  [0] => ‘’
)
Array: (
  [0] => ‘’
)
Array: (
  [0] => ‘’
)
$x = string[0] : ‘’
$x = string[1] : ‘ ’
Array: (
  [0] => ‘ ’
)
Array: (
  [0] => ‘ ’
)
Array: (
  [0] => ‘ ’
)
$x = string[1] : ‘ ’
$x = string[2] : ‘ 1’
Array: (
  [0] => ‘ 1’
)
Array: (
  [0] => ‘ 1’
)
Array: (
  [0] => ‘ 1’
)
$x = string[2] : ‘ 1’
$x = string[3] : ‘ 3 ’
Array: (
  [0] => ‘ 3 ’
)
Array: (
  [0] => ‘ 3 ’
)
Array: (
  [0] => ‘ 3 ’
)
$x = string[3] : ‘ 3 ’
$x = string[1] : ‘1’
Array: (
  [0] => ‘1’
)
Array: (
  [0] => ‘1’
)
Array: (
  [0] => ‘1’
)
$x = string[1] : ‘1’
$x = string[1] : ‘0’
Array: (
  [0] => ‘0’
)
Array: (
  [0] => ‘0’
)
Array: (
  [0] => ‘0’
)
$x = string[1] : ‘0’
$x = string[2] : ‘-1’
Array: (
  [0] => ‘-1’
)
Array: (
  [0] => ‘-1’
)
Array: (
  [0] => ‘-1’
)
$x = string[2] : ‘-1’
$x = string[2] : ‘42’
Array: (
  [0] => ‘42’
)
Array: (
  [0] => ‘42’
)
Array: (
  [0] => ‘42’
)
$x = string[2] : ‘42’
$x = string[3] : ‘1.3’
Array: (
  [0] => ‘1.3’
)
Array: (
  [0] => ‘1.3’
)
Array: (
  [0] => ‘1.3’
)
$x = string[3] : ‘1.3’
$x = string[3] : ‘0.0’
Array: (
  [0] => ‘0.0’
)
Array: (
  [0] => ‘0.0’
)
Array: (
  [0] => ‘0.0’
)
$x = string[3] : ‘0.0’
$x = string[6] : ‘-1.305’
Array: (
  [0] => ‘-1.305’
)
Array: (
  [0] => ‘-1.305’
)
Array: (
  [0] => ‘-1.305’
)
$x = string[6] : ‘-1.305’
$x = string[4] : ‘true’
Array: (
  [0] => ‘true’
)
Array: (
  [0] => ‘true’
)
Array: (
  [0] => ‘true’
)
$x = string[4] : ‘true’
$x = string[5] : ‘false’
Array: (
  [0] => ‘false’
)
Array: (
  [0] => ‘false’
)
Array: (
  [0] => ‘false’
)
$x = string[5] : ‘false’
$x = string[4] : ‘null’
Array: (
  [0] => ‘null’
)
Array: (
  [0] => ‘null’
)
Array: (
  [0] => ‘null’
)
$x = string[4] : ‘null’
$x = string[6] : ‘123str’
Array: (
  [0] => ‘123str’
)
Array: (
  [0] => ‘123str’
)
Array: (
  [0] => ‘123str’
)
$x = string[6] : ‘123str’
$x = string[6] : ‘str123’
Array: (
  [0] => ‘str123’
)
Array: (
  [0] => ‘str123’
)
Array: (
  [0] => ‘str123’
)
$x = string[6] : ‘str123’
$x = string[10] : ‘123, "str"’
Array: (
  [0] => ‘123, "str"’
)
Array: (
  [0] => ‘123, "str"’
)
Array: (
  [0] => ‘123, "str"’
)
$x = string[10] : ‘123, "str"’
$x = string[8] : ‘0xCC00F9’
Array: (
  [0] => ‘0xCC00F9’
)
Array: (
  [0] => ‘0xCC00F9’
)
Array: (
  [0] => ‘0xCC00F9’
)
$x = string[8] : ‘0xCC00F9’
$x = string[4] : ‘0123’
Array: (
  [0] => ‘0123’
)
Array: (
  [0] => ‘0123’
)
Array: (
  [0] => ‘0123’
)
$x = string[4] : ‘0123’
$x = array()
array()
array()
null $x = array()
$x = Array: (
    [1 (int)] => string[6] : ‘string’
)
Array: (
  [1] => ‘string’
)
Array: (
  [1] => ‘string’
)
Array: (
  [1] => ‘string’
)
$x = Array: (
    [1 (int)] => string[6] : ‘string’
)
$x = Array: (
    [0 (int)] => bool : ( = false )
    [1 (int)] => int : 1
    [2 (int)] => float : 1.3
    [3 (int)] => string[6] : ‘123str’
    [4 (int)] => string[6] : ‘str123’
    [5 (int)] => null : ( = NULL )
)
Array: (
  [0] => b false
  [1] => 1
  [2] => 1.3
  [3] => ‘123str’
  [4] => ‘str123’
  [5] => null
)
Array: (
  [0] => b false
  [1] => 1
  [2] => 1.3
  [3] => ‘123str’
  [4] => ‘str123’
  [5] => null
)
Array: (
  [0] => b false
  [1] => 1
  [2] => 1.3
  [3] => ‘123str’
  [4] => ‘str123’
  [5] => null
)
$x = Array: (
    [0 (int)] => bool : ( = false )
    [1 (int)] => int : 1
    [2 (int)] => float : 1.3
    [3 (int)] => string[6] : ‘123str’
    [4 (int)] => string[6] : ‘str123’
    [5 (int)] => null : ( = NULL )
)
$x = Object: (
    Class: stdClass (
    )
)
array()
array()
null $x = Object: (
    Class: stdClass (
    )
)
$x = Object: (
    Class: TestObjectToString (
        property: test3 = string[11] : ‘some string’
        property: test1 = null : ( = NULL )
        property: test2 = bool : 1 ( = true )
        method: __toString
        method: print_it
    )
)
Array: (
  [test3] => ‘some string’
  [test1] => null
  [test2] => b true
)
Array: (
  [test3] => ‘some string’
  [test1] => null
  [test2] => b true
)
Array: (
  [test3] => ‘some string’
  [test1] => null
  [test2] => b true
)
$x = Object: (
    Class: TestObjectToString (
        property: test3 = string[11] : ‘some string’
        property: test1 = null : ( = NULL )
        property: test2 = bool : 1 ( = true )
        method: __toString
        method: print_it
    )
)
$x = resource : Resource id #85 ( = RESOURCE )
Array: (
  [0] => Resource id #85
)
Array: (
  [0] => Resource id #85
)
Array: (
  [0] => Resource id #85
)
$x = resource : Resource id #85 ( = RESOURCE )
  1. Notice: Undefined index: notset
‡ 1

Uses an external library

Array testing is_array() count() empty() count() > 0 isset ( $x[0] ) ‡1 array_key_exists ( 0, $x ) ‡1 isset ( $x['foo'] ) ‡1 key() current() $x['foo'] $x['foo']['bar'] array_filter() Array testing
Array testing is_array() count() empty() count() > 0 isset ( $x[0] ) ‡1 array_key_exists ( 0, $x ) ‡1 isset ( $x['foo'] ) ‡1 key() current() $x['foo'] $x['foo']['bar'] array_filter() Array testing
$x = null : ( = NULL )
false 0 true false false null
#2 )
false null
#3 )
null
#4 )
null null null
#5 )
$x = null : ( = NULL )
$x = null : ( = NULL )
false 0 true false false null
#2 )
false null
#3 )
null
#4 )
null null null
#5 )
$x = null : ( = NULL )
$x = bool : ( = false )
false 1 true true false null
#2 )
false null
#3 )
null
#4 )
null null null
#5 )
$x = bool : ( = false )
$x = bool : 1 ( = true )
false 1 false true false null
#2 )
false null
#3 )
null
#4 )
null null null
#5 )
$x = bool : 1 ( = true )
$x = int : 1
false 1 false true false null
#2 )
false null
#3 )
null
#4 )
null null null
#5 )
$x = int : 1
$x = int : 0
false 1 true true false null
#2 )
false null
#3 )
null
#4 )
null null null
#5 )
$x = int : 0
$x = int : -1
false 1 false true false null
#2 )
false null
#3 )
null
#4 )
null null null
#5 )
$x = int : -1
$x = int : 42
false 1 false true false null
#2 )
false null
#3 )
null
#4 )
null null null
#5 )
$x = int : 42
†i8$x = int : 13369593
false 1 false true false null
#2 )
false null
#3 )
null
#4 )
null null null
#5 )
†i8$x = int : 13369593
†i9$x = int : 42
false 1 false true false null
#2 )
false null
#3 )
null
#4 )
null null null
#5 )
†i9$x = int : 42
†ia$x = int : 57
false 1 false true false null
#2 )
false null
#3 )
null
#4 )
null null null
#5 )
†ia$x = int : 57
$x = float : 1.3
false 1 false true false null
#2 )
false null
#3 )
null
#4 )
null null null
#5 )
$x = float : 1.3
$x = float : 0.005
false 1 false true false null
#2 )
false null
#3 )
null
#4 )
null null null
#5 )
$x = float : 0.005
$x = float : 0
false 1 true true false null
#2 )
false null
#3 )
null
#4 )
null null null
#5 )
$x = float : 0
$x = float : -1.3
false 1 false true false null
#2 )
false null
#3 )
null
#4 )
null null null
#5 )
$x = float : -1.3
†f5$x = float : NAN
false 1 false true false null
#2 )
false null
#3 )
null
#4 )
null null null
#5 )
†f5$x = float : NAN
†f6$x = float : NAN
false 1 false true false null
#2 )
false null
#3 )
null
#4 )
null null null
#5 )
†f6$x = float : NAN
†f7$x = float : -INF
false 1 false true false null
#2 )
false null
#3 )
null
#4 )
null null null
#5 )
†f7$x = float : -INF
†f8$x = float : INF
false 1 false true false null
#2 )
false null
#3 )
null
#4 )
null null null
#5 )
†f8$x = float : INF
†f9$x = float : 123450000
false 1 false true false null
#2 )
false null
#3 )
null
#4 )
null null null
#5 )
†f9$x = float : 123450000
$x = string[0] : ‘’
false 1 true true false null
#2 )
false null
#3 )
null
#4 )
‘’

#6 )
#7 )
‘’

#6 )
#7 )
#8 )
#7 )
null
#5 )
$x = string[0] : ‘’
$x = string[1] : ‘ ’
false 1 false true true null
#2 )
false null
#3 )
null
#4 )
‘ ’

#6 )
‘ ’

#6 )
#8 )
null
#5 )
$x = string[1] : ‘ ’
$x = string[2] : ‘ 1’
false 1 false true true null
#2 )
false null
#3 )
null
#4 )
‘ ’

#6 )
‘ ’

#6 )
#8 )
null
#5 )
$x = string[2] : ‘ 1’
$x = string[3] : ‘ 3 ’
false 1 false true true null
#2 )
false null
#3 )
null
#4 )
‘ ’

#6 )
‘ ’

#6 )
#8 )
null
#5 )
$x = string[3] : ‘ 3 ’
$x = string[1] : ‘1’
false 1 false true true null
#2 )
false null
#3 )
null
#4 )
‘1’

#6 )
‘1’

#6 )
#8 )
null
#5 )
$x = string[1] : ‘1’
$x = string[1] : ‘0’
false 1 true true true null
#2 )
false null
#3 )
null
#4 )
‘0’

#6 )
‘0’

#6 )
#8 )
null
#5 )
$x = string[1] : ‘0’
$x = string[2] : ‘-1’
false 1 false true true null
#2 )
false null
#3 )
null
#4 )
‘-’

#6 )
‘-’

#6 )
#8 )
null
#5 )
$x = string[2] : ‘-1’
$x = string[2] : ‘42’
false 1 false true true null
#2 )
false null
#3 )
null
#4 )
‘4’

#6 )
‘4’

#6 )
#8 )
null
#5 )
$x = string[2] : ‘42’
$x = string[3] : ‘1.3’
false 1 false true true null
#2 )
false null
#3 )
null
#4 )
‘1’

#6 )
‘1’

#6 )
#8 )
null
#5 )
$x = string[3] : ‘1.3’
$x = string[3] : ‘0.0’
false 1 false true true null
#2 )
false null
#3 )
null
#4 )
‘0’

#6 )
‘0’

#6 )
#8 )
null
#5 )
$x = string[3] : ‘0.0’
$x = string[6] : ‘-1.305’
false 1 false true true null
#2 )
false null
#3 )
null
#4 )
‘-’

#6 )
‘-’

#6 )
#8 )
null
#5 )
$x = string[6] : ‘-1.305’
$x = string[4] : ‘true’
false 1 false true true null
#2 )
false null
#3 )
null
#4 )
‘t’

#6 )
‘t’

#6 )
#8 )
null
#5 )
$x = string[4] : ‘true’
$x = string[5] : ‘false’
false 1 false true true null
#2 )
false null
#3 )
null
#4 )
‘f’

#6 )
‘f’

#6 )
#8 )
null
#5 )
$x = string[5] : ‘false’
$x = string[4] : ‘null’
false 1 false true true null
#2 )
false null
#3 )
null
#4 )
‘n’

#6 )
‘n’

#6 )
#8 )
null
#5 )
$x = string[4] : ‘null’
$x = string[6] : ‘123str’
false 1 false true true null
#2 )
false null
#3 )
null
#4 )
‘1’

#6 )
‘1’

#6 )
#8 )
null
#5 )
$x = string[6] : ‘123str’
$x = string[6] : ‘str123’
false 1 false true true null
#2 )
false null
#3 )
null
#4 )
‘s’

#6 )
‘s’

#6 )
#8 )
null
#5 )
$x = string[6] : ‘str123’
$x = string[10] : ‘123, "str"’
false 1 false true true null
#2 )
false null
#3 )
null
#4 )
‘1’

#6 )
‘1’

#6 )
#8 )
null
#5 )
$x = string[10] : ‘123, "str"’
$x = string[8] : ‘0xCC00F9’
false 1 false true true null
#2 )
false null
#3 )
null
#4 )
‘0’

#6 )
‘0’

#6 )
#8 )
null
#5 )
$x = string[8] : ‘0xCC00F9’
$x = string[4] : ‘0123’
false 1 false true true null
#2 )
false null
#3 )
null
#4 )
‘0’

#6 )
‘0’

#6 )
#8 )
null
#5 )
$x = string[4] : ‘0123’
$x = array()
true 0 true false false false false null b false
null
#9 )
null
#9 )
array()
$x = array()
$x = Array: (
    [1 (int)] => string[6] : ‘string’
)
true 1 false true false false false 1
‘string’
null
#9 )
null
#9 )
Array: (
  [1] => ‘string’
)
$x = Array: (
    [1 (int)] => string[6] : ‘string’
)
$x = Array: (
    [0 (int)] => bool : ( = false )
    [1 (int)] => int : 1
    [2 (int)] => float : 1.3
    [3 (int)] => string[6] : ‘123str’
    [4 (int)] => string[6] : ‘str123’
    [5 (int)] => null : ( = NULL )
)
true 6 false true true true false 0
b false
null
#9 )
null
#9 )
Array: (
  [1] => 1
  [2] => 1.3
  [3] => ‘123str’
  [4] => ‘str123’
)
$x = Array: (
    [0 (int)] => bool : ( = false )
    [1 (int)] => int : 1
    [2 (int)] => float : 1.3
    [3 (int)] => string[6] : ‘123str’
    [4 (int)] => string[6] : ‘str123’
    [5 (int)] => null : ( = NULL )
)
$x = Object: (
    Class: stdClass (
    )
)
false 1 false true
Fatal error ( #10 )
false
Fatal error ( #10 )
null b false

Fatal error ( #10 )

Fatal error ( #10 )
null
#5 )
$x = Object: (
    Class: stdClass (
    )
)
$x = Object: (
    Class: TestObject (
        property: test1 = null : ( = NULL )
        property: test2 = bool : 1 ( = true )
        method: print_it
    )
)
false 1 false true
Fatal error ( #10 )
false
Fatal error ( #10 )
‘test1’
null
Fatal error ( #10 )

Fatal error ( #10 )
null
#5 )
$x = Object: (
    Class: TestObject (
        property: test1 = null : ( = NULL )
        property: test2 = bool : 1 ( = true )
        method: print_it
    )
)
$x = Object: (
    Class: TestObjectToString (
        property: test3 = string[11] : ‘some string’
        property: test1 = null : ( = NULL )
        property: test2 = bool : 1 ( = true )
        method: __toString
        method: print_it
    )
)
false 1 false true
Fatal error ( #10 )
false
Fatal error ( #10 )
‘test3’
‘some string’

Fatal error ( #10 )

Fatal error ( #10 )
null
#5 )
$x = Object: (
    Class: TestObjectToString (
        property: test3 = string[11] : ‘some string’
        property: test1 = null : ( = NULL )
        property: test2 = bool : 1 ( = true )
        method: __toString
        method: print_it
    )
)
$x = resource : Resource id #89 ( = RESOURCE )
false 1 false true false null
#2 )
false null
#3 )
null
#4 )
null null null
#5 )
$x = resource : Resource id #89 ( = RESOURCE )
  1. Notice: Undefined index: notset
  2. Warning: array_key_exists() expects parameter 2 to be array, null/boolean/integer/double/string/object/resource given
  3. Warning: key() expects parameter 1 to be array, null/boolean/integer/double/string/object/resource given
  4. Warning: current() expects parameter 1 to be array, null/boolean/integer/double/string/object/resource given
  5. Warning: array_filter() expects parameter 1 to be array, null/boolean/integer/double/string/object/resource given
  6. Warning: Illegal string offset 'foo'
  7. Notice: Uninitialized string offset: 0
  8. Warning: Illegal string offset 'bar'
  9. Notice: Undefined index: foo
  10. Fatal error: Cannot use object of type stdClass/TestObject/TestObjectToString as array
‡ 1

Whether to use isset() or array_key_exists() depends on what you want to know:

  • isset( $array[$key] ) will tell you whether the array key exists and has been assigned a value.
    Used on its own it will give undesired results when used on strings as characters within a string can be approached using the $x[] syntax as well.
    Also, it will cause fatal errors when used on objects.
  • array_key_exists( $key, $array ) will tell you only whether the array key exists, but will not check whether it has a value assigned to it.
    Used on its own, it will show a warning if $array is not an array

This said, we can concluded that to avoid warnings and undesired results you will always have to use an is_array() first.
Also note that isset() is faster than array_key_exists(), but as said above, will return false if no value has been assigned.

Objects settype ( $copy, 'object' ) (object) CastToType::_object ( $x, false ) ‡1 is_object() is_a ( $x, 'TestObject' ) instanceof TestObject get_class() get_parent_class() is_subclass_of ( $x, 'TestObject' ) Objects
Objects settype ( $copy, 'object' ) (object) CastToType::_object ( $x, false ) ‡1 is_object() is_a ( $x, 'TestObject' ) instanceof TestObject get_class() get_parent_class() is_subclass_of ( $x, 'TestObject' ) Objects
$x = null : ( = NULL )
Object: (
  Class: stdClass (
  )
)
Object: (
  Class: stdClass (
  )
)
null false false false false
#2 )
false false $x = null : ( = NULL )
$x = null : ( = NULL )
Object: (
  Class: stdClass (
  )
)
Object: (
  Class: stdClass (
  )
)
null false false false false
#2 )
false false $x = null : ( = NULL )
$x = bool : ( = false )
Object: (
  Class: stdClass (
    property: scalar = b false
  )
)
Object: (
  Class: stdClass (
    property: scalar = b false
  )
)
Object: (
  Class: stdClass (
    property: scalar = b false
  )
)
false false false false
#3 )
false false $x = bool : ( = false )
$x = bool : 1 ( = true )
Object: (
  Class: stdClass (
    property: scalar = b true
  )
)
Object: (
  Class: stdClass (
    property: scalar = b true
  )
)
Object: (
  Class: stdClass (
    property: scalar = b true
  )
)
false false false false
#3 )
false false $x = bool : 1 ( = true )
$x = int : 1
Object: (
  Class: stdClass (
    property: scalar = 1
  )
)
Object: (
  Class: stdClass (
    property: scalar = 1
  )
)
Object: (
  Class: stdClass (
    property: scalar = 1
  )
)
false false false false
#3 )
false false $x = int : 1
$x = int : 0
Object: (
  Class: stdClass (
    property: scalar = 0
  )
)
Object: (
  Class: stdClass (
    property: scalar = 0
  )
)
Object: (
  Class: stdClass (
    property: scalar = 0
  )
)
false false false false
#3 )
false false $x = int : 0
$x = int : -1
Object: (
  Class: stdClass (
    property: scalar = -1
  )
)
Object: (
  Class: stdClass (
    property: scalar = -1
  )
)
Object: (
  Class: stdClass (
    property: scalar = -1
  )
)
false false false false
#3 )
false false $x = int : -1
$x = int : 42
Object: (
  Class: stdClass (
    property: scalar = 42
  )
)
Object: (
  Class: stdClass (
    property: scalar = 42
  )
)
Object: (
  Class: stdClass (
    property: scalar = 42
  )
)
false false false false
#3 )
false false $x = int : 42
†i8$x = int : 13369593
Object: (
  Class: stdClass (
    property: scalar = 13369593
  )
)
Object: (
  Class: stdClass (
    property: scalar = 13369593
  )
)
Object: (
  Class: stdClass (
    property: scalar = 13369593
  )
)
false false false false
#3 )
false false †i8$x = int : 13369593
†i9$x = int : 42
Object: (
  Class: stdClass (
    property: scalar = 42
  )
)
Object: (
  Class: stdClass (
    property: scalar = 42
  )
)
Object: (
  Class: stdClass (
    property: scalar = 42
  )
)
false false false false
#3 )
false false †i9$x = int : 42
†ia$x = int : 57
Object: (
  Class: stdClass (
    property: scalar = 57
  )
)
Object: (
  Class: stdClass (
    property: scalar = 57
  )
)
Object: (
  Class: stdClass (
    property: scalar = 57
  )
)
false false false false
#3 )
false false †ia$x = int : 57
$x = float : 1.3
Object: (
  Class: stdClass (
    property: scalar = 1.3
  )
)
Object: (
  Class: stdClass (
    property: scalar = 1.3
  )
)
Object: (
  Class: stdClass (
    property: scalar = 1.3
  )
)
false false false false
#3 )
false false $x = float : 1.3
$x = float : 0.005
Object: (
  Class: stdClass (
    property: scalar = 0.005
  )
)
Object: (
  Class: stdClass (
    property: scalar = 0.005
  )
)
Object: (
  Class: stdClass (
    property: scalar = 0.005
  )
)
false false false false
#3 )
false false $x = float : 0.005
$x = float : 0
Object: (
  Class: stdClass (
    property: scalar = 0
  )
)
Object: (
  Class: stdClass (
    property: scalar = 0
  )
)
Object: (
  Class: stdClass (
    property: scalar = 0
  )
)
false false false false
#3 )
false false $x = float : 0
$x = float : -1.3
Object: (
  Class: stdClass (
    property: scalar = -1.3
  )
)
Object: (
  Class: stdClass (
    property: scalar = -1.3
  )
)
Object: (
  Class: stdClass (
    property: scalar = -1.3
  )
)
false false false false
#3 )
false false $x = float : -1.3
†f5$x = float : NAN
Object: (
  Class: stdClass (
    property: scalar = NAN
  )
)
Object: (
  Class: stdClass (
    property: scalar = NAN
  )
)
Object: (
  Class: stdClass (
    property: scalar = NAN
  )
)
false false false false
#3 )
false false †f5$x = float : NAN
†f6$x = float : NAN
Object: (
  Class: stdClass (
    property: scalar = NAN
  )
)
Object: (
  Class: stdClass (
    property: scalar = NAN
  )
)
Object: (
  Class: stdClass (
    property: scalar = NAN
  )
)
false false false false
#3 )
false false †f6$x = float : NAN
†f7$x = float : -INF
Object: (
  Class: stdClass (
    property: scalar = -INF
  )
)
Object: (
  Class: stdClass (
    property: scalar = -INF
  )
)
Object: (
  Class: stdClass (
    property: scalar = -INF
  )
)
false false false false
#3 )
false false †f7$x = float : -INF
†f8$x = float : INF
Object: (
  Class: stdClass (
    property: scalar = INF
  )
)
Object: (
  Class: stdClass (
    property: scalar = INF
  )
)
Object: (
  Class: stdClass (
    property: scalar = INF
  )
)
false false false false
#3 )
false false †f8$x = float : INF
†f9$x = float : 123450000
Object: (
  Class: stdClass (
    property: scalar = 123450000
  )
)
Object: (
  Class: stdClass (
    property: scalar = 123450000
  )
)
Object: (
  Class: stdClass (
    property: scalar = 123450000
  )
)
false false false false
#3 )
false false †f9$x = float : 123450000
$x = string[0] : ‘’
Object: (
  Class: stdClass (
    property: scalar = ‘’
  )
)
Object: (
  Class: stdClass (
    property: scalar = ‘’
  )
)
null false false false false
#3 )
false false $x = string[0] : ‘’
$x = string[1] : ‘ ’
Object: (
  Class: stdClass (
    property: scalar = ‘ ’
  )
)
Object: (
  Class: stdClass (
    property: scalar = ‘ ’
  )
)
Object: (
  Class: stdClass (
    property: scalar = ‘ ’
  )
)
false false false false
#3 )
false false $x = string[1] : ‘ ’
$x = string[2] : ‘ 1’
Object: (
  Class: stdClass (
    property: scalar = ‘ 1’
  )
)
Object: (
  Class: stdClass (
    property: scalar = ‘ 1’
  )
)
Object: (
  Class: stdClass (
    property: scalar = ‘ 1’
  )
)
false false false false
#3 )
false false $x = string[2] : ‘ 1’
$x = string[3] : ‘ 3 ’
Object: (
  Class: stdClass (
    property: scalar = ‘ 3 ’
  )
)
Object: (
  Class: stdClass (
    property: scalar = ‘ 3 ’
  )
)
Object: (
  Class: stdClass (
    property: scalar = ‘ 3 ’
  )
)
false false false false
#3 )
false false $x = string[3] : ‘ 3 ’
$x = string[1] : ‘1’
Object: (
  Class: stdClass (
    property: scalar = ‘1’
  )
)
Object: (
  Class: stdClass (
    property: scalar = ‘1’
  )
)
Object: (
  Class: stdClass (
    property: scalar = ‘1’
  )
)
false false false false
#3 )
false false $x = string[1] : ‘1’
$x = string[1] : ‘0’
Object: (
  Class: stdClass (
    property: scalar = ‘0’
  )
)
Object: (
  Class: stdClass (
    property: scalar = ‘0’
  )
)
Object: (
  Class: stdClass (
    property: scalar = ‘0’
  )
)
false false false false
#3 )
false false $x = string[1] : ‘0’
$x = string[2] : ‘-1’
Object: (
  Class: stdClass (
    property: scalar = ‘-1’
  )
)
Object: (
  Class: stdClass (
    property: scalar = ‘-1’
  )
)
Object: (
  Class: stdClass (
    property: scalar = ‘-1’
  )
)
false false false false
#3 )
false false $x = string[2] : ‘-1’
$x = string[2] : ‘42’
Object: (
  Class: stdClass (
    property: scalar = ‘42’
  )
)
Object: (
  Class: stdClass (
    property: scalar = ‘42’
  )
)
Object: (
  Class: stdClass (
    property: scalar = ‘42’
  )
)
false false false false
#3 )
false false $x = string[2] : ‘42’
$x = string[3] : ‘1.3’
Object: (
  Class: stdClass (
    property: scalar = ‘1.3’
  )
)
Object: (
  Class: stdClass (
    property: scalar = ‘1.3’
  )
)
Object: (
  Class: stdClass (
    property: scalar = ‘1.3’
  )
)
false false false false
#3 )
false false $x = string[3] : ‘1.3’
$x = string[3] : ‘0.0’
Object: (
  Class: stdClass (
    property: scalar = ‘0.0’
  )
)
Object: (
  Class: stdClass (
    property: scalar = ‘0.0’
  )
)
Object: (
  Class: stdClass (
    property: scalar = ‘0.0’
  )
)
false false false false
#3 )
false false $x = string[3] : ‘0.0’
$x = string[6] : ‘-1.305’
Object: (
  Class: stdClass (
    property: scalar = ‘-1.305’
  )
)
Object: (
  Class: stdClass (
    property: scalar = ‘-1.305’
  )
)
Object: (
  Class: stdClass (
    property: scalar = ‘-1.305’
  )
)
false false false false
#3 )
false false $x = string[6] : ‘-1.305’
$x = string[4] : ‘true’
Object: (
  Class: stdClass (
    property: scalar = ‘true’
  )
)
Object: (
  Class: stdClass (
    property: scalar = ‘true’
  )
)
Object: (
  Class: stdClass (
    property: scalar = ‘true’
  )
)
false false false false
#3 )
false false $x = string[4] : ‘true’
$x = string[5] : ‘false’
Object: (
  Class: stdClass (
    property: scalar = ‘false’
  )
)
Object: (
  Class: stdClass (
    property: scalar = ‘false’
  )
)
Object: (
  Class: stdClass (
    property: scalar = ‘false’
  )
)
false false false false
#3 )
false false $x = string[5] : ‘false’
$x = string[4] : ‘null’
Object: (
  Class: stdClass (
    property: scalar = ‘null’
  )
)
Object: (
  Class: stdClass (
    property: scalar = ‘null’
  )
)
Object: (
  Class: stdClass (
    property: scalar = ‘null’
  )
)
false false false false
#3 )
false false $x = string[4] : ‘null’
$x = string[6] : ‘123str’
Object: (
  Class: stdClass (
    property: scalar = ‘123str’
  )
)
Object: (
  Class: stdClass (
    property: scalar = ‘123str’
  )
)
Object: (
  Class: stdClass (
    property: scalar = ‘123str’
  )
)
false false false false
#3 )
false false $x = string[6] : ‘123str’
$x = string[6] : ‘str123’
Object: (
  Class: stdClass (
    property: scalar = ‘str123’
  )
)
Object: (
  Class: stdClass (
    property: scalar = ‘str123’
  )
)
Object: (
  Class: stdClass (
    property: scalar = ‘str123’
  )
)
false false false false
#3 )
false false $x = string[6] : ‘str123’
$x = string[10] : ‘123, "str"’
Object: (
  Class: stdClass (
    property: scalar = ‘123, "str"’
  )
)
Object: (
  Class: stdClass (
    property: scalar = ‘123, "str"’
  )
)
Object: (
  Class: stdClass (
    property: scalar = ‘123, "str"’
  )
)
false false false false
#3 )
false false $x = string[10] : ‘123, "str"’
$x = string[8] : ‘0xCC00F9’
Object: (
  Class: stdClass (
    property: scalar = ‘0xCC00F9’
  )
)
Object: (
  Class: stdClass (
    property: scalar = ‘0xCC00F9’
  )
)
Object: (
  Class: stdClass (
    property: scalar = ‘0xCC00F9’
  )
)
false false false false
#3 )
false false $x = string[8] : ‘0xCC00F9’
$x = string[4] : ‘0123’
Object: (
  Class: stdClass (
    property: scalar = ‘0123’
  )
)
Object: (
  Class: stdClass (
    property: scalar = ‘0123’
  )
)
Object: (
  Class: stdClass (
    property: scalar = ‘0123’
  )
)
false false false false
#3 )
false false $x = string[4] : ‘0123’
$x = array()
Object: (
  Class: stdClass (
  )
)
Object: (
  Class: stdClass (
  )
)
null false false false false
#3 )
false false $x = array()
$x = Array: (
    [1 (int)] => string[6] : ‘string’
)
Object: (
  Class: stdClass (
  )
)
Object: (
  Class: stdClass (
  )
)
Object: (
  Class: stdClass (
    property: 1 = ‘string’
  )
)
false false false false
#3 )
false false $x = Array: (
    [1 (int)] => string[6] : ‘string’
)
$x = Array: (
    [0 (int)] => bool : ( = false )
    [1 (int)] => int : 1
    [2 (int)] => float : 1.3
    [3 (int)] => string[6] : ‘123str’
    [4 (int)] => string[6] : ‘str123’
    [5 (int)] => null : ( = NULL )
)
Object: (
  Class: stdClass (
  )
)
Object: (
  Class: stdClass (
  )
)
Object: (
  Class: stdClass (
    property: 0 = b false
    property: 1 = 1
    property: 2 = 1.3
    property: 3 = ‘123str’
    property: 4 = ‘str123’
    property: 5 = null   )
)
false false false false
#3 )
false false $x = Array: (
    [0 (int)] => bool : ( = false )
    [1 (int)] => int : 1
    [2 (int)] => float : 1.3
    [3 (int)] => string[6] : ‘123str’
    [4 (int)] => string[6] : ‘str123’
    [5 (int)] => null : ( = NULL )
)
$x = Array: (
    [s (string)] => string[6] : ‘simple’
    [m (string)] => Array:     (
        [0 (int)] => string[5] : ‘test1’
        [1 (int)] => string[5] : ‘test2’
    )
)
Object: (
  Class: stdClass (
    property: s = ‘simple’
    property: m (array) Array:     (
      [0] => ‘test1’
      [1] => ‘test2’
    )
  )
)
Object: (
  Class: stdClass (
    property: s = ‘simple’
    property: m (array) Array:     (
      [0] => ‘test1’
      [1] => ‘test2’
    )
  )
)
Object: (
  Class: stdClass (
    property: s = ‘simple’
    property: m (array) Array:     (
      [0] => ‘test1’
      [1] => ‘test2’
    )
  )
)
false false false false
#3 )
false false $x = Array: (
    [s (string)] => string[6] : ‘simple’
    [m (string)] => Array:     (
        [0 (int)] => string[5] : ‘test1’
        [1 (int)] => string[5] : ‘test2’
    )
)
$x = Object: (
    Class: stdClass (
    )
)
Object: (
  Class: stdClass (
  )
)
Object: (
  Class: stdClass (
  )
)
null true false false ‘stdClass’
false false $x = Object: (
    Class: stdClass (
    )
)
$x = Object: (
    Class: TestObject (
        property: test1 = null : ( = NULL )
        property: test2 = bool : 1 ( = true )
        method: print_it
    )
)
Object: (
  Class: TestObject (
    property: test1 = null     property: test2 = b true
    method: print_it
  )
)
Object: (
  Class: TestObject (
    property: test1 = null     property: test2 = b true
    method: print_it
  )
)
Object: (
  Class: TestObject (
    property: test1 = null     property: test2 = b true
    method: print_it
  )
)
true true true ‘TestObject’
false false $x = Object: (
    Class: TestObject (
        property: test1 = null : ( = NULL )
        property: test2 = bool : 1 ( = true )
        method: print_it
    )
)
$x = Object: (
    Class: TestObjectToString (
        property: test3 = string[11] : ‘some string’
        property: test1 = null : ( = NULL )
        property: test2 = bool : 1 ( = true )
        method: __toString
        method: print_it
    )
)
Object: (
  Class: TestObjectToString (
    property: test3 = ‘some string’
    property: test1 = null     property: test2 = b true
    method: __toString
    method: print_it
  )
)
Object: (
  Class: TestObjectToString (
    property: test3 = ‘some string’
    property: test1 = null     property: test2 = b true
    method: __toString
    method: print_it
  )
)
Object: (
  Class: TestObjectToString (
    property: test3 = ‘some string’
    property: test1 = null     property: test2 = b true
    method: __toString
    method: print_it
  )
)
true true true ‘TestObjectToString’
‘TestObject’
true $x = Object: (
    Class: TestObjectToString (
        property: test3 = string[11] : ‘some string’
        property: test1 = null : ( = NULL )
        property: test2 = bool : 1 ( = true )
        method: __toString
        method: print_it
    )
)
$x = resource : Resource id #93 ( = RESOURCE )
Object: (
  Class: stdClass (
    property: scalar = Resource id #93
  )
)
Object: (
  Class: stdClass (
    property: scalar = Resource id #93
  )
)
Object: (
  Class: stdClass (
    property: scalar = Resource id #93
  )
)
false false false false
#3 )
false false $x = resource : Resource id #93 ( = RESOURCE )
  1. Notice: Undefined index: notset
  2. Warning: get_class() called without object from outside a class
  3. Warning: get_class() expects parameter 1 to be object, boolean/integer/double/string/array/resource given
‡ 1

Uses an external library

Resources is_resource() get_resource_type() Resources
Resources is_resource() get_resource_type() Resources
$x = null : ( = NULL )
false null
#2 )
$x = null : ( = NULL )
$x = null : ( = NULL )
false null
#2 )
$x = null : ( = NULL )
$x = bool : ( = false )
false null
#2 )
$x = bool : ( = false )
$x = bool : 1 ( = true )
false null
#2 )
$x = bool : 1 ( = true )
$x = int : 1
false null
#2 )
$x = int : 1
$x = int : 0
false null
#2 )
$x = int : 0
$x = int : -1
false null
#2 )
$x = int : -1
$x = int : 42
false null
#2 )
$x = int : 42
†i8$x = int : 13369593
false null
#2 )
†i8$x = int : 13369593
†i9$x = int : 42
false null
#2 )
†i9$x = int : 42
†ia$x = int : 57
false null
#2 )
†ia$x = int : 57
$x = float : 1.3
false null
#2 )
$x = float : 1.3
$x = float : 0.005
false null
#2 )
$x = float : 0.005
$x = float : 0
false null
#2 )
$x = float : 0
$x = float : -1.3
false null
#2 )
$x = float : -1.3
†f5$x = float : NAN
false null
#2 )
†f5$x = float : NAN
†f6$x = float : NAN
false null
#2 )
†f6$x = float : NAN
†f7$x = float : -INF
false null
#2 )
†f7$x = float : -INF
†f8$x = float : INF
false null
#2 )
†f8$x = float : INF
†f9$x = float : 123450000
false null
#2 )
†f9$x = float : 123450000
$x = string[0] : ‘’
false null
#2 )
$x = string[0] : ‘’
$x = string[1] : ‘ ’
false null
#2 )
$x = string[1] : ‘ ’
$x = string[2] : ‘ 1’
false null
#2 )
$x = string[2] : ‘ 1’
$x = string[3] : ‘ 3 ’
false null
#2 )
$x = string[3] : ‘ 3 ’
$x = string[1] : ‘1’
false null
#2 )
$x = string[1] : ‘1’
$x = string[1] : ‘0’
false null
#2 )
$x = string[1] : ‘0’
$x = string[2] : ‘-1’
false null
#2 )
$x = string[2] : ‘-1’
$x = string[2] : ‘42’
false null
#2 )
$x = string[2] : ‘42’
$x = string[3] : ‘1.3’
false null
#2 )
$x = string[3] : ‘1.3’
$x = string[3] : ‘0.0’
false null
#2 )
$x = string[3] : ‘0.0’
$x = string[6] : ‘-1.305’
false null
#2 )
$x = string[6] : ‘-1.305’
$x = string[4] : ‘true’
false null
#2 )
$x = string[4] : ‘true’
$x = string[5] : ‘false’
false null
#2 )
$x = string[5] : ‘false’
$x = string[4] : ‘null’
false null
#2 )
$x = string[4] : ‘null’
$x = string[6] : ‘123str’
false null
#2 )
$x = string[6] : ‘123str’
$x = string[6] : ‘str123’
false null
#2 )
$x = string[6] : ‘str123’
$x = string[10] : ‘123, "str"’
false null
#2 )
$x = string[10] : ‘123, "str"’
$x = string[8] : ‘0xCC00F9’
false null
#2 )
$x = string[8] : ‘0xCC00F9’
$x = string[4] : ‘0123’
false null
#2 )
$x = string[4] : ‘0123’
$x = array()
false null
#2 )
$x = array()
$x = Array: (
    [1 (int)] => string[6] : ‘string’
)
false null
#2 )
$x = Array: (
    [1 (int)] => string[6] : ‘string’
)
$x = Array: (
    [0 (int)] => bool : ( = false )
    [1 (int)] => int : 1
    [2 (int)] => float : 1.3
    [3 (int)] => string[6] : ‘123str’
    [4 (int)] => string[6] : ‘str123’
    [5 (int)] => null : ( = NULL )
)
false null
#2 )
$x = Array: (
    [0 (int)] => bool : ( = false )
    [1 (int)] => int : 1
    [2 (int)] => float : 1.3
    [3 (int)] => string[6] : ‘123str’
    [4 (int)] => string[6] : ‘str123’
    [5 (int)] => null : ( = NULL )
)
$x = Object: (
    Class: stdClass (
    )
)
false null
#2 )
$x = Object: (
    Class: stdClass (
    )
)
$x = Object: (
    Class: TestObjectToString (
        property: test3 = string[11] : ‘some string’
        property: test1 = null : ( = NULL )
        property: test2 = bool : 1 ( = true )
        method: __toString
        method: print_it
    )
)
false null
#2 )
$x = Object: (
    Class: TestObjectToString (
        property: test3 = string[11] : ‘some string’
        property: test1 = null : ( = NULL )
        property: test2 = bool : 1 ( = true )
        method: __toString
        method: print_it
    )
)
$x = resource : Resource id #97 ( = RESOURCE )
true ‘stream’ $x = resource : Resource id #97 ( = RESOURCE )
$x = resource : Resource id #99 ( = RESOURCE )
true ‘gd’ $x = resource : Resource id #99 ( = RESOURCE )
  1. Notice: Undefined index: notset
  2. Warning: get_resource_type() expects parameter 1 to be resource, null/boolean/integer/double/string/array/object given
Basic Arithmetic $x = ++$x ‡1 $x = $x++ ‡1 $x = --$x ‡1 $x = $x-- ‡1 -$x $x + 0 $x - 0 $x * 1 $x / 1 $x % 1 Basic Arithmetic
Basic Arithmetic $x = ++$x ‡1 $x = $x++ ‡1 $x = --$x ‡1 $x = $x-- ‡1 -$x $x + 0 $x - 0 $x * 1 $x / 1 $x % 1 Basic Arithmetic
$x = null : ( = NULL )
1 null null null 0
0 0
0
0
0
$x = null : ( = NULL )
$x = null : ( = NULL )
1 null null null 0
0 0
0
0
0
$x = null : ( = NULL )
$x = bool : ( = false )
b false
b false
b false
b false
0
0 0
0
0
0
$x = bool : ( = false )
$x = bool : 1 ( = true )
b true
b true
b true
b true
-1
1 1
1
1
0
$x = bool : 1 ( = true )
$x = int : 1
2 1 0 1 -1
1 1
1
1
0
$x = int : 1
$x = int : 0
1 0 -1 0 0
0 0
0
0
0
$x = int : 0
$x = int : -1
0 -1 -2 -1 1
-1 -1
-1
-1
0
$x = int : -1
$x = int : 42
43 42 41 42 -42
42 42
42
42
0
$x = int : 42
†i8$x = int : 13369593
13369594 13369593 13369592 13369593 -13369593
13369593 13369593
13369593
13369593
0
†i8$x = int : 13369593
†i9$x = int : 42
43 42 41 42 -42
42 42
42
42
0
†i9$x = int : 42
†ia$x = int : 57
58 57 56 57 -57
57 57
57
57
0
†ia$x = int : 57
$x = float : 1.3
2.3 1.3 0.3 1.3 -1.3
1.3 1.3
1.3
1.3
0
$x = float : 1.3
$x = float : 0.005
1.005 0.005 -0.995 0.005 -0.005
0.005 0.005
0.005
0.005
0
$x = float : 0.005
$x = float : 0
1 0 -1 0 0
0 0
0
0
0
$x = float : 0
$x = float : -1.3
-0.3 -1.3 -2.3 -1.3 1.3
-1.3 -1.3
-1.3
-1.3
0
$x = float : -1.3
†f5$x = float : NAN
NAN NAN NAN NAN NAN
NAN NAN
NAN
NAN
0
†f5$x = float : NAN
†f6$x = float : NAN
NAN NAN NAN NAN NAN
NAN NAN
NAN
NAN
0
†f6$x = float : NAN
†f7$x = float : -INF
-INF -INF -INF -INF INF
-INF -INF
-INF
-INF
0
†f7$x = float : -INF
†f8$x = float : INF
INF INF INF INF -INF
INF INF
INF
INF
0
†f8$x = float : INF
†f9$x = float : 123450000
123450001 123450000 123449999 123450000 -123450000
123450000 123450000
123450000
123450000
0
†f9$x = float : 123450000
$x = string[0] : ‘’
‘1’
‘’
-1 ‘’
0
0 0
0
0
0
$x = string[0] : ‘’
$x = string[1] : ‘ ’
‘ ’
‘ ’
‘ ’
‘ ’
0
0 0
0
0
0
$x = string[1] : ‘ ’
$x = string[2] : ‘ 1’
2 ‘ 1’
0 ‘ 1’
-1
1 1
1
1
0
$x = string[2] : ‘ 1’
$x = string[3] : ‘ 3 ’
‘ 3 ’
‘ 3 ’
‘ 3 ’
‘ 3 ’
-3
3 3
3
3
0
$x = string[3] : ‘ 3 ’
$x = string[1] : ‘1’
2 ‘1’
0 ‘1’
-1
1 1
1
1
0
$x = string[1] : ‘1’
$x = string[1] : ‘0’
1 ‘0’
-1 ‘0’
0
0 0
0
0
0
$x = string[1] : ‘0’
$x = string[2] : ‘-1’
0 ‘-1’
-2 ‘-1’
1
-1 -1
-1
-1
0
$x = string[2] : ‘-1’
$x = string[2] : ‘42’
43 ‘42’
41 ‘42’
-42
42 42
42
42
0
$x = string[2] : ‘42’
$x = string[3] : ‘1.3’
2.3 ‘1.3’
0.3 ‘1.3’
-1.3
1.3 1.3
1.3
1.3
0
$x = string[3] : ‘1.3’
$x = string[3] : ‘0.0’
1 ‘0.0’
-1 ‘0.0’
0
0 0
0
0
0
$x = string[3] : ‘0.0’
$x = string[6] : ‘-1.305’
-0.305 ‘-1.305’
-2.305 ‘-1.305’
1.305
-1.305 -1.305
-1.305
-1.305
0
$x = string[6] : ‘-1.305’
$x = string[4] : ‘true’
‘truf’
‘true’
‘true’
‘true’
0
0 0
0
0
0
$x = string[4] : ‘true’
$x = string[5] : ‘false’
‘falsf’
‘false’
‘false’
‘false’
0
0 0
0
0
0
$x = string[5] : ‘false’
$x = string[4] : ‘null’
‘nulm’
‘null’
‘null’
‘null’
0
0 0
0
0
0
$x = string[4] : ‘null’
$x = string[6] : ‘123str’
‘123sts’
‘123str’
‘123str’
‘123str’
-123
123 123
123
123
0
$x = string[6] : ‘123str’
$x = string[6] : ‘str123’
‘str124’
‘str123’
‘str123’
‘str123’
0
0 0
0
0
0
$x = string[6] : ‘str123’
$x = string[10] : ‘123, "str"’
‘123, "str"’
‘123, "str"’
‘123, "str"’
‘123, "str"’
-123
123 123
123
123
0
$x = string[10] : ‘123, "str"’
$x = string[8] : ‘0xCC00F9’
13369594 ‘0xCC00F9’
13369592 ‘0xCC00F9’
-13369593
13369593 13369593
13369593
13369593
0
$x = string[8] : ‘0xCC00F9’
$x = string[4] : ‘0123’
124 ‘0123’
122 ‘0123’
-123
123 123
123
123
0
$x = string[4] : ‘0123’
$x = array()
array()
array()
array()
array()

Fatal error ( #2 )

Fatal error ( #2 )

Fatal error ( #2 )

Fatal error ( #2 )

Fatal error ( #2 )
0
$x = array()
$x = Array: (
    [1 (int)] => string[6] : ‘string’
)
Array: (
  [1] => ‘string’
)
Array: (
  [1] => ‘string’
)
Array: (
  [1] => ‘string’
)
Array: (
  [1] => ‘string’
)

Fatal error ( #2 )

Fatal error ( #2 )

Fatal error ( #2 )

Fatal error ( #2 )

Fatal error ( #2 )
0
$x = Array: (
    [1 (int)] => string[6] : ‘string’
)
$x = Array: (
    [0 (int)] => bool : ( = false )
    [1 (int)] => int : 1
    [2 (int)] => float : 1.3
    [3 (int)] => string[6] : ‘123str’
    [4 (int)] => string[6] : ‘str123’
    [5 (int)] => null : ( = NULL )
)
Array: (
  [0] => b false
  [1] => 1
  [2] => 1.3
  [3] => ‘123str’
  [4] => ‘str123’
  [5] => null
)
Array: (
  [0] => b false
  [1] => 1
  [2] => 1.3
  [3] => ‘123str’
  [4] => ‘str123’
  [5] => null
)
Array: (
  [0] => b false
  [1] => 1
  [2] => 1.3
  [3] => ‘123str’
  [4] => ‘str123’
  [5] => null
)
Array: (
  [0] => b false
  [1] => 1
  [2] => 1.3
  [3] => ‘123str’
  [4] => ‘str123’
  [5] => null
)

Fatal error ( #2 )

Fatal error ( #2 )

Fatal error ( #2 )

Fatal error ( #2 )

Fatal error ( #2 )
0
$x = Array: (
    [0 (int)] => bool : ( = false )
    [1 (int)] => int : 1
    [2 (int)] => float : 1.3
    [3 (int)] => string[6] : ‘123str’
    [4 (int)] => string[6] : ‘str123’
    [5 (int)] => null : ( = NULL )
)
$x = Object: (
    Class: stdClass (
    )
)
Object: (
  Class: stdClass (
  )
)
Object: (
  Class: stdClass (
  )
)
Object: (
  Class: stdClass (
  )
)
Object: (
  Class: stdClass (
  )
)
-1

#3 )
1
#3 )
1

#3 )
1

#3 )
1

#3 )
0

#3 )
$x = Object: (
    Class: stdClass (
    )
)
$x = Object: (
    Class: TestObjectToString (
        property: test3 = string[11] : ‘some string’
        property: test1 = null : ( = NULL )
        property: test2 = bool : 1 ( = true )
        method: __toString
        method: print_it
    )
)
Object: (
  Class: TestObjectToString (
    property: test3 = ‘some string’
    property: test1 = null     property: test2 = b true
    method: __toString
    method: print_it
  )
)
Object: (
  Class: TestObjectToString (
    property: test3 = ‘some string’
    property: test1 = null     property: test2 = b true
    method: __toString
    method: print_it
  )
)
Object: (
  Class: TestObjectToString (
    property: test3 = ‘some string’
    property: test1 = null     property: test2 = b true
    method: __toString
    method: print_it
  )
)
Object: (
  Class: TestObjectToString (
    property: test3 = ‘some string’
    property: test1 = null     property: test2 = b true
    method: __toString
    method: print_it
  )
)
-1

#3 )
1
#3 )
1

#3 )
1

#3 )
1

#3 )
0

#3 )
$x = Object: (
    Class: TestObjectToString (
        property: test3 = string[11] : ‘some string’
        property: test1 = null : ( = NULL )
        property: test2 = bool : 1 ( = true )
        method: __toString
        method: print_it
    )
)
$x = resource : Resource id #101 ( = RESOURCE )
Resource id #101
Resource id #101
Resource id #101
Resource id #101
-101
101 101
101
101
0
$x = resource : Resource id #101 ( = RESOURCE )
  1. Notice: Undefined index: notset
  2. Fatal error: Unsupported operand types
  3. Notice: Object of class stdClass/TestObject/TestObjectToString could not be converted to int
‡ 1

Please take note: using the in-/decrementors on SplInt and SplFloat objects may give unexpected (inconsistent) results....

CType Extension ctype_digit() ‡1 ctype_xdigit() ‡1 ctype_alpha() ‡1 ctype_alnum() ‡1 ctype_graph() ‡1 ctype_print() ‡1 ctype_lower() ‡1 ctype_upper() ‡1 ctype_cntrl() ‡1 ctype_punct() ‡1 ctype_space() ‡1 CType Extension
CType Extension ctype_digit() ‡1 ctype_xdigit() ‡1 ctype_alpha() ‡1 ctype_alnum() ‡1 ctype_graph() ‡1 ctype_print() ‡1 ctype_lower() ‡1 ctype_upper() ‡1 ctype_cntrl() ‡1 ctype_punct() ‡1 ctype_space() ‡1 CType Extension
$x = null : ( = NULL )
false false false false false false false false false false false $x = null : ( = NULL )
$x = null : ( = NULL )
false false false false false false false false false false false $x = null : ( = NULL )
$x = bool : ( = false )
false false false false false false false false false false false $x = bool : ( = false )
$x = bool : 1 ( = true )
false false false false false false false false false false false $x = bool : 1 ( = true )
$x = int : 1
false false false false false false false false true false false $x = int : 1
$x = int : 0
false false false false false false false false true false false $x = int : 0
$x = int : -1
false false false false false false false false false false false $x = int : -1
$x = int : 10
false false false false false false false false true false true $x = int : 10
$x = int : 42
false false false false true true false false false true false $x = int : 42
$x = int : 111
false false true true true true true false false false false $x = int : 111
$x = int : 12345
true true false true true true false false false false false $x = int : 12345
†i8$x = int : 13369593
true true false true true true false false false false false †i8$x = int : 13369593
†i9$x = int : 42
false false false false true true false false false true false †i9$x = int : 42
†ia$x = int : 57
true true false true true true false false false false false †ia$x = int : 57
$x = float : 1.3
false false false false false false false false false false false $x = float : 1.3
$x = float : 0.005
false false false false false false false false false false false $x = float : 0.005
$x = float : 0
false false false false false false false false false false false $x = float : 0
$x = float : -1.3
false false false false false false false false false false false $x = float : -1.3
†f5$x = float : NAN
false false false false false false false false false false false †f5$x = float : NAN
†f6$x = float : NAN
false false false false false false false false false false false †f6$x = float : NAN
†f7$x = float : -INF
false false false false false false false false false false false †f7$x = float : -INF
†f8$x = float : INF
false false false false false false false false false false false †f8$x = float : INF
†f9$x = float : 123450000
false false false false false false false false false false false †f9$x = float : 123450000
$x = string[0] : ‘’
false false false false false false false false false false false $x = string[0] : ‘’
$x = string[1] : ‘ ’
false false false false false true false false false false true $x = string[1] : ‘ ’
$x = string[2] : ‘ 1’
false false false false false true false false false false false $x = string[2] : ‘ 1’
$x = string[3] : ‘ 3 ’
false false false false false true false false false false false $x = string[3] : ‘ 3 ’
$x = string[1] : ‘1’
true true false true true true false false false false false $x = string[1] : ‘1’
$x = string[1] : ‘0’
true true false true true true false false false false false $x = string[1] : ‘0’
$x = string[2] : ‘-1’
false false false false true true false false false false false $x = string[2] : ‘-1’
$x = string[2] : ‘42’
true true false true true true false false false false false $x = string[2] : ‘42’
$x = string[3] : ‘1.3’
false false false false true true false false false false false $x = string[3] : ‘1.3’
$x = string[3] : ‘0.0’
false false false false true true false false false false false $x = string[3] : ‘0.0’
$x = string[6] : ‘-1.305’
false false false false true true false false false false false $x = string[6] : ‘-1.305’
$x = string[4] : ‘true’
false false true true true true true false false false false $x = string[4] : ‘true’
$x = string[5] : ‘false’
false false true true true true true false false false false $x = string[5] : ‘false’
$x = string[4] : ‘null’
false false true true true true true false false false false $x = string[4] : ‘null’
$x = string[6] : ‘123str’
false false false true true true false false false false false $x = string[6] : ‘123str’
$x = string[6] : ‘str123’
false false false true true true false false false false false $x = string[6] : ‘str123’
$x = string[10] : ‘123, "str"’
false false false false false true false false false false false $x = string[10] : ‘123, "str"’
$x = string[9] : ‘123,"str"’
false false false false true true false false false false false $x = string[9] : ‘123,"str"’
†sk$x = string[12] : ‘123, "str" ’
false false false false false false false false false false false †sk$x = string[12] : ‘123, "str" ’
$x = string[6] : ‘AF036C’
false true false true true true false false false false false $x = string[6] : ‘AF036C’
$x = string[3] : ‘FOO’
false false true true true true false true false false false $x = string[3] : ‘FOO’
†sn$x = string[4] : ‘ ’
false false false false false false false false true false true †sn$x = string[4] : ‘ ’
$x = string[5] : ‘*&$()’
false false false false true true false false false true false $x = string[5] : ‘*&$()’
†sp$x = string[4] : ‘ ’
false false false false false false false false true false false †sp$x = string[4] : ‘ ’
$x = string[8] : ‘0xCC00F9’
false false false true true true false false false false false $x = string[8] : ‘0xCC00F9’
$x = string[4] : ‘0123’
true true false true true true false false false false false $x = string[4] : ‘0123’
$x = string[27] : ‘Iñtërnâtiônàlizætiøn’
false false false false false false false false false false false $x = string[27] : ‘Iñtërnâtiônàlizætiøn’
$x = array()
false false false false false false false false false false false $x = array()
$x = Array: (
    [1 (int)] => string[6] : ‘string’
)
false false false false false false false false false false false $x = Array: (
    [1 (int)] => string[6] : ‘string’
)
$x = Array: (
    [0 (int)] => bool : ( = false )
    [1 (int)] => int : 1
    [2 (int)] => float : 1.3
    [3 (int)] => string[6] : ‘123str’
    [4 (int)] => string[6] : ‘str123’
    [5 (int)] => null : ( = NULL )
)
false false false false false false false false false false false $x = Array: (
    [0 (int)] => bool : ( = false )
    [1 (int)] => int : 1
    [2 (int)] => float : 1.3
    [3 (int)] => string[6] : ‘123str’
    [4 (int)] => string[6] : ‘str123’
    [5 (int)] => null : ( = NULL )
)
$x = Object: (
    Class: stdClass (
    )
)
false false false false false false false false false false false $x = Object: (
    Class: stdClass (
    )
)
$x = Object: (
    Class: TestObjectToString (
        property: test3 = string[11] : ‘some string’
        property: test1 = null : ( = NULL )
        property: test2 = bool : 1 ( = true )
        method: __toString
        method: print_it
    )
)
false false false false false false false false false false false $x = Object: (
    Class: TestObjectToString (
        property: test3 = string[11] : ‘some string’
        property: test1 = null : ( = NULL )
        property: test2 = bool : 1 ( = true )
        method: __toString
        method: print_it
    )
)
$x = resource : Resource id #105 ( = RESOURCE )
false false false false false false false false false false false $x = resource : Resource id #105 ( = RESOURCE )
  1. Notice: Undefined index: notset
‡ 1

Important: Integers between -128 and 255 are interpreted as the ASCII value pointing to a character (negative values have 256 added in order to allow characters in the Extended ASCII range).
In any other case, integers are interpreted as a string containing the decimal digits of the integer.

Filter Extension - bool/int/float filter_var (…) ‡1 ‡2 filter_var (…) ‡2 filter_var (…) ‡2 filter_var (…) ‡2 filter_var (…) ‡2 filter_var (…) ‡2 filter_var (…) ‡2 filter_var (…) ‡2 Filter Extension - bool/int/float
Filter Extension - bool/int/float filter_var (…) ‡1 ‡2 filter_var (…) ‡2 filter_var (…) ‡2 filter_var (…) ‡2 filter_var (…) ‡2 filter_var (…) ‡2 filter_var (…) ‡2 filter_var (…) ‡2 Filter Extension - bool/int/float
$x = null : ( = NULL )
false null null null ‘’
null ‘’
‘’
$x = null : ( = NULL )
$x = null : ( = NULL )
false null null null ‘’
null ‘’
‘’
$x = null : ( = NULL )
$x = bool : ( = false )
false null null null ‘’
null ‘’
‘’
$x = bool : ( = false )
$x = bool : 1 ( = true )
true 1 1 1 ‘1’
1 ‘1’
‘1’
$x = bool : 1 ( = true )
$x = int : 1
true 1 1 1 ‘1’
1 ‘1’
‘1’
$x = int : 1
$x = int : 0
false 0 null 0 ‘0’
0 ‘0’
‘0’
$x = int : 0
$x = int : -1
null -1 null -1 ‘-1’
-1 ‘-1’
‘-1’
$x = int : -1
$x = int : 42
null 42 42 42 ‘42’
42 ‘42’
‘42’
$x = int : 42
†i8$x = int : 13369593
null 13369593 null 13369593 ‘13369593’
13369593 ‘13369593’
‘13369593’
†i8$x = int : 13369593
†i9$x = int : 42
null 42 42 42 ‘42’
42 ‘42’
‘42’
†i9$x = int : 42
†ia$x = int : 57
null 57 null 57 ‘57’
57 ‘57’
‘57’
†ia$x = int : 57
$x = float : 1.3
null null null null ‘13’
1.3 ‘13’
‘1.3’
$x = float : 1.3
$x = float : 0.005
null null null null ‘0005’
0.005 ‘0005’
‘0.005’
$x = float : 0.005
$x = float : 0
false