多分世界一詳細な PHP キャスト結果対応表
この記事は2023/04/01に作成されました。
PHP を本格的に書き始めてから 7 年くらい経ちます。
最近はキャスト結果がどうなるかググることは少なくなってきましたが、それでも結果の一覧表があったら便利だろうなぁ、と思って 7 年サボりました。
ブログを書くネタを考えていたときに、ふとこの課題を思い出したのでさっと PHP コードを書いてみました。表も合わせて紹介します。
PHP のキャスト結果表
先に手持ちの PHP 8.1.13 で後述するコードを実行した結果表をご紹介します。
※ブログに張り付けている関係上、後で紹介するコードの結果とスタイルが違いますがご了承ください。
PHP cast results table(PHP Version: 8.1.13)
(int) | (float) | (string) | (bool) | (array) | (object) | |
---|---|---|---|---|---|---|
1 | int(1) (truthy) | float(1) (truthy) | string(1) "1" (truthy) | bool(true) (truthy) | array(1) { [0]=> int(1) } (truthy) | object(stdClass)#50 (1) { ["scalar"]=> int(1) } (truthy) |
0 | int(0) (falsy) | float(0) (falsy) | string(1) "0" (falsy) | bool(false) (falsy) | array(1) { [0]=> int(0) } (truthy) | object(stdClass)#50 (1) { ["scalar"]=> int(0) } (truthy) |
00 | int(0) (falsy) | float(0) (falsy) | string(1) "0" (falsy) | bool(false) (falsy) | array(1) { [0]=> int(0) } (truthy) | object(stdClass)#50 (1) { ["scalar"]=> int(0) } (truthy) |
-1 | int(-1) (truthy) | float(-1) (truthy) | string(2) "-1" (truthy) | bool(true) (truthy) | array(1) { [0]=> int(-1) } (truthy) | object(stdClass)#50 (1) { ["scalar"]=> int(-1) } (truthy) |
-0 | int(0) (falsy) | float(0) (falsy) | string(1) "0" (falsy) | bool(false) (falsy) | array(1) { [0]=> int(0) } (truthy) | object(stdClass)#50 (1) { ["scalar"]=> int(0) } (truthy) |
0x00000 | int(0) (falsy) | float(0) (falsy) | string(1) "0" (falsy) | bool(false) (falsy) | array(1) { [0]=> int(0) } (truthy) | object(stdClass)#50 (1) { ["scalar"]=> int(0) } (truthy) |
true | int(1) (truthy) | float(1) (truthy) | string(1) "1" (truthy) | bool(true) (truthy) | array(1) { [0]=> bool(true) } (truthy) | object(stdClass)#50 (1) { ["scalar"]=> bool(true) } (truthy) |
false | int(0) (falsy) | float(0) (falsy) | string(0) "" (falsy) | bool(false) (falsy) | array(1) { [0]=> bool(false) } (truthy) | object(stdClass)#50 (1) { ["scalar"]=> bool(false) } (truthy) |
1.1 | int(1) (truthy) | float(1.1) (truthy) | string(3) "1.1" (truthy) | bool(true) (truthy) | array(1) { [0]=> float(1.1) } (truthy) | object(stdClass)#50 (1) { ["scalar"]=> float(1.1) } (truthy) |
1.1111111 | int(1) (truthy) | float(1.1111111) (truthy) | string(9) "1.1111111" (truthy) | bool(true) (truthy) | array(1) { [0]=> float(1.1111111) } (truthy) | object(stdClass)#50 (1) { ["scalar"]=> float(1.1111111) } (truthy) |
0.0 | int(0) (falsy) | float(0) (falsy) | string(1) "0" (falsy) | bool(false) (falsy) | array(1) { [0]=> float(0) } (truthy) | object(stdClass)#50 (1) { ["scalar"]=> float(0) } (truthy) |
0.0000000 | int(0) (falsy) | float(0) (falsy) | string(1) "0" (falsy) | bool(false) (falsy) | array(1) { [0]=> float(0) } (truthy) | object(stdClass)#50 (1) { ["scalar"]=> float(0) } (truthy) |
0.0000001 | int(0) (falsy) | float(1.0E-7) (truthy) | string(6) "1.0E-7" (truthy) | bool(true) (truthy) | array(1) { [0]=> float(1.0E-7) } (truthy) | object(stdClass)#50 (1) { ["scalar"]=> float(1.0E-7) } (truthy) |
0.5000000 | int(0) (falsy) | float(0.5) (truthy) | string(3) "0.5" (truthy) | bool(true) (truthy) | array(1) { [0]=> float(0.5) } (truthy) | object(stdClass)#50 (1) { ["scalar"]=> float(0.5) } (truthy) |
-1.1 | int(-1) (truthy) | float(-1.1) (truthy) | string(4) "-1.1" (truthy) | bool(true) (truthy) | array(1) { [0]=> float(-1.1) } (truthy) | object(stdClass)#50 (1) { ["scalar"]=> float(-1.1) } (truthy) |
-1.1111111 | int(-1) (truthy) | float(-1.1111111) (truthy) | string(10) "-1.1111111" (truthy) | bool(true) (truthy) | array(1) { [0]=> float(-1.1111111) } (truthy) | object(stdClass)#50 (1) { ["scalar"]=> float(-1.1111111) } (truthy) |
-0.0 | int(0) (falsy) | float(-0) (falsy) | string(2) "-0" (truthy) | bool(false) (falsy) | array(1) { [0]=> float(-0) } (truthy) | object(stdClass)#50 (1) { ["scalar"]=> float(-0) } (truthy) |
-0.0000000 | int(0) (falsy) | float(-0) (falsy) | string(2) "-0" (truthy) | bool(false) (falsy) | array(1) { [0]=> float(-0) } (truthy) | object(stdClass)#50 (1) { ["scalar"]=> float(-0) } (truthy) |
-0.0000001 | int(0) (falsy) | float(-1.0E-7) (truthy) | string(7) "-1.0E-7" (truthy) | bool(true) (truthy) | array(1) { [0]=> float(-1.0E-7) } (truthy) | object(stdClass)#50 (1) { ["scalar"]=> float(-1.0E-7) } (truthy) |
-0.5000000 | int(0) (falsy) | float(-0.5) (truthy) | string(4) "-0.5" (truthy) | bool(true) (truthy) | array(1) { [0]=> float(-0.5) } (truthy) | object(stdClass)#50 (1) { ["scalar"]=> float(-0.5) } (truthy) |
null | int(0) (falsy) | float(0) (falsy) | string(0) "" (falsy) | bool(false) (falsy) | array(0) { } (falsy) | object(stdClass)#50 (0) { } (truthy) |
'text' | int(0) (falsy) | float(0) (falsy) | string(4) "text" (truthy) | bool(true) (truthy) | array(1) { [0]=> string(4) "text" } (truthy) | object(stdClass)#50 (1) { ["scalar"]=> string(4) "text" } (truthy) |
"\x49\x20\x6c\x6f\x76\x65\x20\x50\x48\x50\x2e" | int(0) (falsy) | float(0) (falsy) | string(11) "I love PHP." (truthy) | bool(true) (truthy) | array(1) { [0]=> string(11) "I love PHP." } (truthy) | object(stdClass)#50 (1) { ["scalar"]=> string(11) "I love PHP." } (truthy) |
'' | int(0) (falsy) | float(0) (falsy) | string(0) "" (falsy) | bool(false) (falsy) | array(1) { [0]=> string(0) "" } (truthy) | object(stdClass)#50 (1) { ["scalar"]=> string(0) "" } (truthy) |
"\x00" | int(0) (falsy) | float(0) (falsy) | string(1) "" (truthy) | bool(true) (truthy) | array(1) { [0]=> string(1) "" } (truthy) | object(stdClass)#50 (1) { ["scalar"]=> string(1) "" } (truthy) |
' ' | int(0) (falsy) | float(0) (falsy) | string(1) " " (truthy) | bool(true) (truthy) | array(1) { [0]=> string(1) " " } (truthy) | object(stdClass)#50 (1) { ["scalar"]=> string(1) " " } (truthy) |
' ' | int(0) (falsy) | float(0) (falsy) | string(3) " " (truthy) | bool(true) (truthy) | array(1) { [0]=> string(3) " " } (truthy) | object(stdClass)#50 (1) { ["scalar"]=> string(3) " " } (truthy) |
'0' | int(0) (falsy) | float(0) (falsy) | string(3) "0" (truthy) | bool(true) (truthy) | array(1) { [0]=> string(3) "0" } (truthy) | object(stdClass)#50 (1) { ["scalar"]=> string(3) "0" } (truthy) |
'1' | int(1) (truthy) | float(1) (truthy) | string(1) "1" (truthy) | bool(true) (truthy) | array(1) { [0]=> string(1) "1" } (truthy) | object(stdClass)#50 (1) { ["scalar"]=> string(1) "1" } (truthy) |
'0' | int(0) (falsy) | float(0) (falsy) | string(1) "0" (falsy) | bool(false) (falsy) | array(1) { [0]=> string(1) "0" } (truthy) | object(stdClass)#50 (1) { ["scalar"]=> string(1) "0" } (truthy) |
'00' | int(0) (falsy) | float(0) (falsy) | string(2) "00" (truthy) | bool(true) (truthy) | array(1) { [0]=> string(2) "00" } (truthy) | object(stdClass)#50 (1) { ["scalar"]=> string(2) "00" } (truthy) |
'-1' | int(-1) (truthy) | float(-1) (truthy) | string(2) "-1" (truthy) | bool(true) (truthy) | array(1) { [0]=> string(2) "-1" } (truthy) | object(stdClass)#50 (1) { ["scalar"]=> string(2) "-1" } (truthy) |
'-0' | int(0) (falsy) | float(-0) (falsy) | string(2) "-0" (truthy) | bool(true) (truthy) | array(1) { [0]=> string(2) "-0" } (truthy) | object(stdClass)#50 (1) { ["scalar"]=> string(2) "-0" } (truthy) |
'true' | int(0) (falsy) | float(0) (falsy) | string(4) "true" (truthy) | bool(true) (truthy) | array(1) { [0]=> string(4) "true" } (truthy) | object(stdClass)#50 (1) { ["scalar"]=> string(4) "true" } (truthy) |
'false' | int(0) (falsy) | float(0) (falsy) | string(5) "false" (truthy) | bool(true) (truthy) | array(1) { [0]=> string(5) "false" } (truthy) | object(stdClass)#50 (1) { ["scalar"]=> string(5) "false" } (truthy) |
'1.1' | int(1) (truthy) | float(1.1) (truthy) | string(3) "1.1" (truthy) | bool(true) (truthy) | array(1) { [0]=> string(3) "1.1" } (truthy) | object(stdClass)#50 (1) { ["scalar"]=> string(3) "1.1" } (truthy) |
'1.1111111' | int(1) (truthy) | float(1.1111111) (truthy) | string(9) "1.1111111" (truthy) | bool(true) (truthy) | array(1) { [0]=> string(9) "1.1111111" } (truthy) | object(stdClass)#50 (1) { ["scalar"]=> string(9) "1.1111111" } (truthy) |
'0.0' | int(0) (falsy) | float(0) (falsy) | string(3) "0.0" (truthy) | bool(true) (truthy) | array(1) { [0]=> string(3) "0.0" } (truthy) | object(stdClass)#50 (1) { ["scalar"]=> string(3) "0.0" } (truthy) |
'0.0000000' | int(0) (falsy) | float(0) (falsy) | string(9) "0.0000000" (truthy) | bool(true) (truthy) | array(1) { [0]=> string(9) "0.0000000" } (truthy) | object(stdClass)#50 (1) { ["scalar"]=> string(9) "0.0000000" } (truthy) |
'0.0000001' | int(0) (falsy) | float(1.0E-7) (truthy) | string(9) "0.0000001" (truthy) | bool(true) (truthy) | array(1) { [0]=> string(9) "0.0000001" } (truthy) | object(stdClass)#50 (1) { ["scalar"]=> string(9) "0.0000001" } (truthy) |
'0.5000000' | int(0) (falsy) | float(0.5) (truthy) | string(9) "0.5000000" (truthy) | bool(true) (truthy) | array(1) { [0]=> string(9) "0.5000000" } (truthy) | object(stdClass)#50 (1) { ["scalar"]=> string(9) "0.5000000" } (truthy) |
'-1.1' | int(-1) (truthy) | float(-1.1) (truthy) | string(4) "-1.1" (truthy) | bool(true) (truthy) | array(1) { [0]=> string(4) "-1.1" } (truthy) | object(stdClass)#50 (1) { ["scalar"]=> string(4) "-1.1" } (truthy) |
'-1.1111111' | int(-1) (truthy) | float(-1.1111111) (truthy) | string(10) "-1.1111111" (truthy) | bool(true) (truthy) | array(1) { [0]=> string(10) "-1.1111111" } (truthy) | object(stdClass)#50 (1) { ["scalar"]=> string(10) "-1.1111111" } (truthy) |
'-0.0' | int(0) (falsy) | float(-0) (falsy) | string(4) "-0.0" (truthy) | bool(true) (truthy) | array(1) { [0]=> string(4) "-0.0" } (truthy) | object(stdClass)#50 (1) { ["scalar"]=> string(4) "-0.0" } (truthy) |
'-0.0000000' | int(0) (falsy) | float(-0) (falsy) | string(10) "-0.0000000" (truthy) | bool(true) (truthy) | array(1) { [0]=> string(10) "-0.0000000" } (truthy) | object(stdClass)#50 (1) { ["scalar"]=> string(10) "-0.0000000" } (truthy) |
'-0.0000001' | int(0) (falsy) | float(-1.0E-7) (truthy) | string(10) "-0.0000001" (truthy) | bool(true) (truthy) | array(1) { [0]=> string(10) "-0.0000001" } (truthy) | object(stdClass)#50 (1) { ["scalar"]=> string(10) "-0.0000001" } (truthy) |
'-0.5000000' | int(0) (falsy) | float(-0.5) (truthy) | string(10) "-0.5000000" (truthy) | bool(true) (truthy) | array(1) { [0]=> string(10) "-0.5000000" } (truthy) | object(stdClass)#50 (1) { ["scalar"]=> string(10) "-0.5000000" } (truthy) |
'null' | int(0) (falsy) | float(0) (falsy) | string(4) "null" (truthy) | bool(true) (truthy) | array(1) { [0]=> string(4) "null" } (truthy) | object(stdClass)#50 (1) { ["scalar"]=> string(4) "null" } (truthy) |
[] | int(0) (falsy) | float(0) (falsy) | error | bool(false) (falsy) | array(0) { } (falsy) | object(stdClass)#50 (0) { } (truthy) |
[[]] | int(1) (truthy) | float(1) (truthy) | error | bool(true) (truthy) | array(1) { [0]=> array(0) { } } (truthy) | object(stdClass)#50 (1) { ["0"]=> array(0) { } } (truthy) |
[[[[[[[]]]]]]] | int(1) (truthy) | float(1) (truthy) | error | bool(true) (truthy) | array(1) { [0]=> array(1) { [0]=> array(1) { [0]=> array(1) { [0]=> array(1) { [0]=> array(1) { [0]=> array(0) { } } } } } } } (truthy) | object(stdClass)#50 (1) { ["0"]=> array(1) { [0]=> array(1) { [0]=> array(1) { [0]=> array(1) { [0]=> array(1) { [0]=> array(0) { } } } } } } } (truthy) |
[1] | int(1) (truthy) | float(1) (truthy) | error | bool(true) (truthy) | array(1) { [0]=> int(1) } (truthy) | object(stdClass)#50 (1) { ["0"]=> int(1) } (truthy) |
[0] | int(1) (truthy) | float(1) (truthy) | error | bool(true) (truthy) | array(1) { [0]=> int(0) } (truthy) | object(stdClass)#50 (1) { ["0"]=> int(0) } (truthy) |
[00] | int(1) (truthy) | float(1) (truthy) | error | bool(true) (truthy) | array(1) { [0]=> int(0) } (truthy) | object(stdClass)#50 (1) { ["0"]=> int(0) } (truthy) |
[-1] | int(1) (truthy) | float(1) (truthy) | error | bool(true) (truthy) | array(1) { [0]=> int(-1) } (truthy) | object(stdClass)#50 (1) { ["0"]=> int(-1) } (truthy) |
[-0] | int(1) (truthy) | float(1) (truthy) | error | bool(true) (truthy) | array(1) { [0]=> int(0) } (truthy) | object(stdClass)#50 (1) { ["0"]=> int(0) } (truthy) |
[0x00000] | int(1) (truthy) | float(1) (truthy) | error | bool(true) (truthy) | array(1) { [0]=> int(0) } (truthy) | object(stdClass)#50 (1) { ["0"]=> int(0) } (truthy) |
[true] | int(1) (truthy) | float(1) (truthy) | error | bool(true) (truthy) | array(1) { [0]=> bool(true) } (truthy) | object(stdClass)#50 (1) { ["0"]=> bool(true) } (truthy) |
[false] | int(1) (truthy) | float(1) (truthy) | error | bool(true) (truthy) | array(1) { [0]=> bool(false) } (truthy) | object(stdClass)#50 (1) { ["0"]=> bool(false) } (truthy) |
[1.1] | int(1) (truthy) | float(1) (truthy) | error | bool(true) (truthy) | array(1) { [0]=> float(1.1) } (truthy) | object(stdClass)#50 (1) { ["0"]=> float(1.1) } (truthy) |
[1.1111111] | int(1) (truthy) | float(1) (truthy) | error | bool(true) (truthy) | array(1) { [0]=> float(1.1111111) } (truthy) | object(stdClass)#50 (1) { ["0"]=> float(1.1111111) } (truthy) |
[0.0] | int(1) (truthy) | float(1) (truthy) | error | bool(true) (truthy) | array(1) { [0]=> float(0) } (truthy) | object(stdClass)#50 (1) { ["0"]=> float(0) } (truthy) |
[0.0000000] | int(1) (truthy) | float(1) (truthy) | error | bool(true) (truthy) | array(1) { [0]=> float(0) } (truthy) | object(stdClass)#50 (1) { ["0"]=> float(0) } (truthy) |
[0.0000001] | int(1) (truthy) | float(1) (truthy) | error | bool(true) (truthy) | array(1) { [0]=> float(1.0E-7) } (truthy) | object(stdClass)#50 (1) { ["0"]=> float(1.0E-7) } (truthy) |
[0.5000000] | int(1) (truthy) | float(1) (truthy) | error | bool(true) (truthy) | array(1) { [0]=> float(0.5) } (truthy) | object(stdClass)#50 (1) { ["0"]=> float(0.5) } (truthy) |
[-1.1] | int(1) (truthy) | float(1) (truthy) | error | bool(true) (truthy) | array(1) { [0]=> float(-1.1) } (truthy) | object(stdClass)#50 (1) { ["0"]=> float(-1.1) } (truthy) |
[-1.1111111] | int(1) (truthy) | float(1) (truthy) | error | bool(true) (truthy) | array(1) { [0]=> float(-1.1111111) } (truthy) | object(stdClass)#50 (1) { ["0"]=> float(-1.1111111) } (truthy) |
[-0.0] | int(1) (truthy) | float(1) (truthy) | error | bool(true) (truthy) | array(1) { [0]=> float(-0) } (truthy) | object(stdClass)#50 (1) { ["0"]=> float(-0) } (truthy) |
[-0.0000000] | int(1) (truthy) | float(1) (truthy) | error | bool(true) (truthy) | array(1) { [0]=> float(-0) } (truthy) | object(stdClass)#50 (1) { ["0"]=> float(-0) } (truthy) |
[-0.0000001] | int(1) (truthy) | float(1) (truthy) | error | bool(true) (truthy) | array(1) { [0]=> float(-1.0E-7) } (truthy) | object(stdClass)#50 (1) { ["0"]=> float(-1.0E-7) } (truthy) |
[-0.5000000] | int(1) (truthy) | float(1) (truthy) | error | bool(true) (truthy) | array(1) { [0]=> float(-0.5) } (truthy) | object(stdClass)#50 (1) { ["0"]=> float(-0.5) } (truthy) |
[null] | int(1) (truthy) | float(1) (truthy) | error | bool(true) (truthy) | array(1) { [0]=> NULL } (truthy) | object(stdClass)#50 (1) { ["0"]=> NULL } (truthy) |
['text'] | int(1) (truthy) | float(1) (truthy) | error | bool(true) (truthy) | array(1) { [0]=> string(4) "text" } (truthy) | object(stdClass)#50 (1) { ["0"]=> string(4) "text" } (truthy) |
["\x49\x20\x6c\x6f\x76\x65\x20\x50\x48\x50\x2e"] | int(1) (truthy) | float(1) (truthy) | error | bool(true) (truthy) | array(1) { [0]=> string(11) "I love PHP." } (truthy) | object(stdClass)#50 (1) { ["0"]=> string(11) "I love PHP." } (truthy) |
[''] | int(1) (truthy) | float(1) (truthy) | error | bool(true) (truthy) | array(1) { [0]=> string(0) "" } (truthy) | object(stdClass)#50 (1) { ["0"]=> string(0) "" } (truthy) |
["\x00"] | int(1) (truthy) | float(1) (truthy) | error | bool(true) (truthy) | array(1) { [0]=> string(1) "" } (truthy) | object(stdClass)#50 (1) { ["0"]=> string(1) "" } (truthy) |
[' '] | int(1) (truthy) | float(1) (truthy) | error | bool(true) (truthy) | array(1) { [0]=> string(1) " " } (truthy) | object(stdClass)#50 (1) { ["0"]=> string(1) " " } (truthy) |
[' '] | int(1) (truthy) | float(1) (truthy) | error | bool(true) (truthy) | array(1) { [0]=> string(3) " " } (truthy) | object(stdClass)#50 (1) { ["0"]=> string(3) " " } (truthy) |
['0'] | int(1) (truthy) | float(1) (truthy) | error | bool(true) (truthy) | array(1) { [0]=> string(3) "0" } (truthy) | object(stdClass)#50 (1) { ["0"]=> string(3) "0" } (truthy) |
['1'] | int(1) (truthy) | float(1) (truthy) | error | bool(true) (truthy) | array(1) { [0]=> string(1) "1" } (truthy) | object(stdClass)#50 (1) { ["0"]=> string(1) "1" } (truthy) |
['0'] | int(1) (truthy) | float(1) (truthy) | error | bool(true) (truthy) | array(1) { [0]=> string(1) "0" } (truthy) | object(stdClass)#50 (1) { ["0"]=> string(1) "0" } (truthy) |
['00'] | int(1) (truthy) | float(1) (truthy) | error | bool(true) (truthy) | array(1) { [0]=> string(2) "00" } (truthy) | object(stdClass)#50 (1) { ["0"]=> string(2) "00" } (truthy) |
['-1'] | int(1) (truthy) | float(1) (truthy) | error | bool(true) (truthy) | array(1) { [0]=> string(2) "-1" } (truthy) | object(stdClass)#50 (1) { ["0"]=> string(2) "-1" } (truthy) |
['-0'] | int(1) (truthy) | float(1) (truthy) | error | bool(true) (truthy) | array(1) { [0]=> string(2) "-0" } (truthy) | object(stdClass)#50 (1) { ["0"]=> string(2) "-0" } (truthy) |
['true'] | int(1) (truthy) | float(1) (truthy) | error | bool(true) (truthy) | array(1) { [0]=> string(4) "true" } (truthy) | object(stdClass)#50 (1) { ["0"]=> string(4) "true" } (truthy) |
['false'] | int(1) (truthy) | float(1) (truthy) | error | bool(true) (truthy) | array(1) { [0]=> string(5) "false" } (truthy) | object(stdClass)#50 (1) { ["0"]=> string(5) "false" } (truthy) |
['1.1'] | int(1) (truthy) | float(1) (truthy) | error | bool(true) (truthy) | array(1) { [0]=> string(3) "1.1" } (truthy) | object(stdClass)#50 (1) { ["0"]=> string(3) "1.1" } (truthy) |
['1.1111111'] | int(1) (truthy) | float(1) (truthy) | error | bool(true) (truthy) | array(1) { [0]=> string(9) "1.1111111" } (truthy) | object(stdClass)#50 (1) { ["0"]=> string(9) "1.1111111" } (truthy) |
['0.0'] | int(1) (truthy) | float(1) (truthy) | error | bool(true) (truthy) | array(1) { [0]=> string(3) "0.0" } (truthy) | object(stdClass)#50 (1) { ["0"]=> string(3) "0.0" } (truthy) |
['0.0000000'] | int(1) (truthy) | float(1) (truthy) | error | bool(true) (truthy) | array(1) { [0]=> string(9) "0.0000000" } (truthy) | object(stdClass)#50 (1) { ["0"]=> string(9) "0.0000000" } (truthy) |
['0.0000001'] | int(1) (truthy) | float(1) (truthy) | error | bool(true) (truthy) | array(1) { [0]=> string(9) "0.0000001" } (truthy) | object(stdClass)#50 (1) { ["0"]=> string(9) "0.0000001" } (truthy) |
['0.5000000'] | int(1) (truthy) | float(1) (truthy) | error | bool(true) (truthy) | array(1) { [0]=> string(9) "0.5000000" } (truthy) | object(stdClass)#50 (1) { ["0"]=> string(9) "0.5000000" } (truthy) |
['-1.1'] | int(1) (truthy) | float(1) (truthy) | error | bool(true) (truthy) | array(1) { [0]=> string(4) "-1.1" } (truthy) | object(stdClass)#50 (1) { ["0"]=> string(4) "-1.1" } (truthy) |
['-1.1111111'] | int(1) (truthy) | float(1) (truthy) | error | bool(true) (truthy) | array(1) { [0]=> string(10) "-1.1111111" } (truthy) | object(stdClass)#50 (1) { ["0"]=> string(10) "-1.1111111" } (truthy) |
['-0.0'] | int(1) (truthy) | float(1) (truthy) | error | bool(true) (truthy) | array(1) { [0]=> string(4) "-0.0" } (truthy) | object(stdClass)#50 (1) { ["0"]=> string(4) "-0.0" } (truthy) |
['-0.0000000'] | int(1) (truthy) | float(1) (truthy) | error | bool(true) (truthy) | array(1) { [0]=> string(10) "-0.0000000" } (truthy) | object(stdClass)#50 (1) { ["0"]=> string(10) "-0.0000000" } (truthy) |
['-0.0000001'] | int(1) (truthy) | float(1) (truthy) | error | bool(true) (truthy) | array(1) { [0]=> string(10) "-0.0000001" } (truthy) | object(stdClass)#50 (1) { ["0"]=> string(10) "-0.0000001" } (truthy) |
['-0.5000000'] | int(1) (truthy) | float(1) (truthy) | error | bool(true) (truthy) | array(1) { [0]=> string(10) "-0.5000000" } (truthy) | object(stdClass)#50 (1) { ["0"]=> string(10) "-0.5000000" } (truthy) |
['null'] | int(1) (truthy) | float(1) (truthy) | error | bool(true) (truthy) | array(1) { [0]=> string(4) "null" } (truthy) | object(stdClass)#50 (1) { ["0"]=> string(4) "null" } (truthy) |
[1, 1] | int(1) (truthy) | float(1) (truthy) | error | bool(true) (truthy) | array(2) { [0]=> int(1) [1]=> int(1) } (truthy) | object(stdClass)#50 (2) { ["0"]=> int(1) ["1"]=> int(1) } (truthy) |
[0, 0] | int(1) (truthy) | float(1) (truthy) | error | bool(true) (truthy) | array(2) { [0]=> int(0) [1]=> int(0) } (truthy) | object(stdClass)#50 (2) { ["0"]=> int(0) ["1"]=> int(0) } (truthy) |
[00, 00] | int(1) (truthy) | float(1) (truthy) | error | bool(true) (truthy) | array(2) { [0]=> int(0) [1]=> int(0) } (truthy) | object(stdClass)#50 (2) { ["0"]=> int(0) ["1"]=> int(0) } (truthy) |
[-1, -1] | int(1) (truthy) | float(1) (truthy) | error | bool(true) (truthy) | array(2) { [0]=> int(-1) [1]=> int(-1) } (truthy) | object(stdClass)#50 (2) { ["0"]=> int(-1) ["1"]=> int(-1) } (truthy) |
[-0, -0] | int(1) (truthy) | float(1) (truthy) | error | bool(true) (truthy) | array(2) { [0]=> int(0) [1]=> int(0) } (truthy) | object(stdClass)#50 (2) { ["0"]=> int(0) ["1"]=> int(0) } (truthy) |
[0x00000, 0x00000] | int(1) (truthy) | float(1) (truthy) | error | bool(true) (truthy) | array(2) { [0]=> int(0) [1]=> int(0) } (truthy) | object(stdClass)#50 (2) { ["0"]=> int(0) ["1"]=> int(0) } (truthy) |
[true, true] | int(1) (truthy) | float(1) (truthy) | error | bool(true) (truthy) | array(2) { [0]=> bool(true) [1]=> bool(true) } (truthy) | object(stdClass)#50 (2) { ["0"]=> bool(true) ["1"]=> bool(true) } (truthy) |
[false, false] | int(1) (truthy) | float(1) (truthy) | error | bool(true) (truthy) | array(2) { [0]=> bool(false) [1]=> bool(false) } (truthy) | object(stdClass)#50 (2) { ["0"]=> bool(false) ["1"]=> bool(false) } (truthy) |
[1.1, 1.1] | int(1) (truthy) | float(1) (truthy) | error | bool(true) (truthy) | array(2) { [0]=> float(1.1) [1]=> float(1.1) } (truthy) | object(stdClass)#50 (2) { ["0"]=> float(1.1) ["1"]=> float(1.1) } (truthy) |
[1.1111111, 1.1111111] | int(1) (truthy) | float(1) (truthy) | error | bool(true) (truthy) | array(2) { [0]=> float(1.1111111) [1]=> float(1.1111111) } (truthy) | object(stdClass)#50 (2) { ["0"]=> float(1.1111111) ["1"]=> float(1.1111111) } (truthy) |
[0.0, 0.0] | int(1) (truthy) | float(1) (truthy) | error | bool(true) (truthy) | array(2) { [0]=> float(0) [1]=> float(0) } (truthy) | object(stdClass)#50 (2) { ["0"]=> float(0) ["1"]=> float(0) } (truthy) |
[0.0000000, 0.0000000] | int(1) (truthy) | float(1) (truthy) | error | bool(true) (truthy) | array(2) { [0]=> float(0) [1]=> float(0) } (truthy) | object(stdClass)#50 (2) { ["0"]=> float(0) ["1"]=> float(0) } (truthy) |
[0.0000001, 0.0000001] | int(1) (truthy) | float(1) (truthy) | error | bool(true) (truthy) | array(2) { [0]=> float(1.0E-7) [1]=> float(1.0E-7) } (truthy) | object(stdClass)#50 (2) { ["0"]=> float(1.0E-7) ["1"]=> float(1.0E-7) } (truthy) |
[0.5000000, 0.5000000] | int(1) (truthy) | float(1) (truthy) | error | bool(true) (truthy) | array(2) { [0]=> float(0.5) [1]=> float(0.5) } (truthy) | object(stdClass)#50 (2) { ["0"]=> float(0.5) ["1"]=> float(0.5) } (truthy) |
[-1.1, -1.1] | int(1) (truthy) | float(1) (truthy) | error | bool(true) (truthy) | array(2) { [0]=> float(-1.1) [1]=> float(-1.1) } (truthy) | object(stdClass)#50 (2) { ["0"]=> float(-1.1) ["1"]=> float(-1.1) } (truthy) |
[-1.1111111, -1.1111111] | int(1) (truthy) | float(1) (truthy) | error | bool(true) (truthy) | array(2) { [0]=> float(-1.1111111) [1]=> float(-1.1111111) } (truthy) | object(stdClass)#50 (2) { ["0"]=> float(-1.1111111) ["1"]=> float(-1.1111111) } (truthy) |
[-0.0, -0.0] | int(1) (truthy) | float(1) (truthy) | error | bool(true) (truthy) | array(2) { [0]=> float(-0) [1]=> float(-0) } (truthy) | object(stdClass)#50 (2) { ["0"]=> float(-0) ["1"]=> float(-0) } (truthy) |
[-0.0000000, -0.0000000] | int(1) (truthy) | float(1) (truthy) | error | bool(true) (truthy) | array(2) { [0]=> float(-0) [1]=> float(-0) } (truthy) | object(stdClass)#50 (2) { ["0"]=> float(-0) ["1"]=> float(-0) } (truthy) |
[-0.0000001, -0.0000001] | int(1) (truthy) | float(1) (truthy) | error | bool(true) (truthy) | array(2) { [0]=> float(-1.0E-7) [1]=> float(-1.0E-7) } (truthy) | object(stdClass)#50 (2) { ["0"]=> float(-1.0E-7) ["1"]=> float(-1.0E-7) } (truthy) |
[-0.5000000, -0.5000000] | int(1) (truthy) | float(1) (truthy) | error | bool(true) (truthy) | array(2) { [0]=> float(-0.5) [1]=> float(-0.5) } (truthy) | object(stdClass)#50 (2) { ["0"]=> float(-0.5) ["1"]=> float(-0.5) } (truthy) |
[null, null] | int(1) (truthy) | float(1) (truthy) | error | bool(true) (truthy) | array(2) { [0]=> NULL [1]=> NULL } (truthy) | object(stdClass)#50 (2) { ["0"]=> NULL ["1"]=> NULL } (truthy) |
['text', 'text'] | int(1) (truthy) | float(1) (truthy) | error | bool(true) (truthy) | array(2) { [0]=> string(4) "text" [1]=> string(4) "text" } (truthy) | object(stdClass)#50 (2) { ["0"]=> string(4) "text" ["1"]=> string(4) "text" } (truthy) |
["\x49\x20\x6c\x6f\x76\x65\x20\x50\x48\x50\x2e", "\x49\x20\x6c\x6f\x76\x65\x20\x50\x48\x50\x2e"] | int(1) (truthy) | float(1) (truthy) | error | bool(true) (truthy) | array(2) { [0]=> string(11) "I love PHP." [1]=> string(11) "I love PHP." } (truthy) | object(stdClass)#50 (2) { ["0"]=> string(11) "I love PHP." ["1"]=> string(11) "I love PHP." } (truthy) |
['', ''] | int(1) (truthy) | float(1) (truthy) | error | bool(true) (truthy) | array(2) { [0]=> string(0) "" [1]=> string(0) "" } (truthy) | object(stdClass)#50 (2) { ["0"]=> string(0) "" ["1"]=> string(0) "" } (truthy) |
["\x00", "\x00"] | int(1) (truthy) | float(1) (truthy) | error | bool(true) (truthy) | array(2) { [0]=> string(1) "" [1]=> string(1) "" } (truthy) | object(stdClass)#50 (2) { ["0"]=> string(1) "" ["1"]=> string(1) "" } (truthy) |
[' ', ' '] | int(1) (truthy) | float(1) (truthy) | error | bool(true) (truthy) | array(2) { [0]=> string(1) " " [1]=> string(1) " " } (truthy) | object(stdClass)#50 (2) { ["0"]=> string(1) " " ["1"]=> string(1) " " } (truthy) |
[' ', ' '] | int(1) (truthy) | float(1) (truthy) | error | bool(true) (truthy) | array(2) { [0]=> string(3) " " [1]=> string(3) " " } (truthy) | object(stdClass)#50 (2) { ["0"]=> string(3) " " ["1"]=> string(3) " " } (truthy) |
['0', '0'] | int(1) (truthy) | float(1) (truthy) | error | bool(true) (truthy) | array(2) { [0]=> string(3) "0" [1]=> string(3) "0" } (truthy) | object(stdClass)#50 (2) { ["0"]=> string(3) "0" ["1"]=> string(3) "0" } (truthy) |
['1', '1'] | int(1) (truthy) | float(1) (truthy) | error | bool(true) (truthy) | array(2) { [0]=> string(1) "1" [1]=> string(1) "1" } (truthy) | object(stdClass)#50 (2) { ["0"]=> string(1) "1" ["1"]=> string(1) "1" } (truthy) |
['0', '0'] | int(1) (truthy) | float(1) (truthy) | error | bool(true) (truthy) | array(2) { [0]=> string(1) "0" [1]=> string(1) "0" } (truthy) | object(stdClass)#50 (2) { ["0"]=> string(1) "0" ["1"]=> string(1) "0" } (truthy) |
['00', '00'] | int(1) (truthy) | float(1) (truthy) | error | bool(true) (truthy) | array(2) { [0]=> string(2) "00" [1]=> string(2) "00" } (truthy) | object(stdClass)#50 (2) { ["0"]=> string(2) "00" ["1"]=> string(2) "00" } (truthy) |
['-1', '-1'] | int(1) (truthy) | float(1) (truthy) | error | bool(true) (truthy) | array(2) { [0]=> string(2) "-1" [1]=> string(2) "-1" } (truthy) | object(stdClass)#50 (2) { ["0"]=> string(2) "-1" ["1"]=> string(2) "-1" } (truthy) |
['-0', '-0'] | int(1) (truthy) | float(1) (truthy) | error | bool(true) (truthy) | array(2) { [0]=> string(2) "-0" [1]=> string(2) "-0" } (truthy) | object(stdClass)#50 (2) { ["0"]=> string(2) "-0" ["1"]=> string(2) "-0" } (truthy) |
['true', 'true'] | int(1) (truthy) | float(1) (truthy) | error | bool(true) (truthy) | array(2) { [0]=> string(4) "true" [1]=> string(4) "true" } (truthy) | object(stdClass)#50 (2) { ["0"]=> string(4) "true" ["1"]=> string(4) "true" } (truthy) |
['false', 'false'] | int(1) (truthy) | float(1) (truthy) | error | bool(true) (truthy) | array(2) { [0]=> string(5) "false" [1]=> string(5) "false" } (truthy) | object(stdClass)#50 (2) { ["0"]=> string(5) "false" ["1"]=> string(5) "false" } (truthy) |
['1.1', '1.1'] | int(1) (truthy) | float(1) (truthy) | error | bool(true) (truthy) | array(2) { [0]=> string(3) "1.1" [1]=> string(3) "1.1" } (truthy) | object(stdClass)#50 (2) { ["0"]=> string(3) "1.1" ["1"]=> string(3) "1.1" } (truthy) |
['1.1111111', '1.1111111'] | int(1) (truthy) | float(1) (truthy) | error | bool(true) (truthy) | array(2) { [0]=> string(9) "1.1111111" [1]=> string(9) "1.1111111" } (truthy) | object(stdClass)#50 (2) { ["0"]=> string(9) "1.1111111" ["1"]=> string(9) "1.1111111" } (truthy) |
['0.0', '0.0'] | int(1) (truthy) | float(1) (truthy) | error | bool(true) (truthy) | array(1) { [0]=> string(3) "0.0" } (truthy) | object(stdClass)#50 (1) { ["0"]=> string(3) "0.0" } (truthy) |
['0.0000000', '0.0000000'] | int(1) (truthy) | float(1) (truthy) | error | bool(true) (truthy) | array(2) { [0]=> string(9) "0.0000000" [1]=> string(9) "0.0000000" } (truthy) | object(stdClass)#50 (2) { ["0"]=> string(9) "0.0000000" ["1"]=> string(9) "0.0000000" } (truthy) |
['0.0000001', '0.0000001'] | int(1) (truthy) | float(1) (truthy) | error | bool(true) (truthy) | array(2) { [0]=> string(9) "0.0000001" [1]=> string(9) "0.0000001" } (truthy) | object(stdClass)#50 (2) { ["0"]=> string(9) "0.0000001" ["1"]=> string(9) "0.0000001" } (truthy) |
['0.5000000', '0.5000000'] | int(1) (truthy) | float(1) (truthy) | error | bool(true) (truthy) | array(2) { [0]=> string(9) "0.5000000" [1]=> string(9) "0.5000000" } (truthy) | object(stdClass)#50 (2) { ["0"]=> string(9) "0.5000000" ["1"]=> string(9) "0.5000000" } (truthy) |
['-1.1', '-1.1'] | int(1) (truthy) | float(1) (truthy) | error | bool(true) (truthy) | array(2) { [0]=> string(4) "-1.1" [1]=> string(4) "-1.1" } (truthy) | object(stdClass)#50 (2) { ["0"]=> string(4) "-1.1" ["1"]=> string(4) "-1.1" } (truthy) |
['-1.1111111', '-1.1111111'] | int(1) (truthy) | float(1) (truthy) | error | bool(true) (truthy) | array(2) { [0]=> string(10) "-1.1111111" [1]=> string(10) "-1.1111111" } (truthy) | object(stdClass)#50 (2) { ["0"]=> string(10) "-1.1111111" ["1"]=> string(10) "-1.1111111" } (truthy) |
['-0.0', '-0.0'] | int(1) (truthy) | float(1) (truthy) | error | bool(true) (truthy) | array(2) { [0]=> string(4) "-0.0" [1]=> string(4) "-0.0" } (truthy) | object(stdClass)#50 (2) { ["0"]=> string(4) "-0.0" ["1"]=> string(4) "-0.0" } (truthy) |
['-0.0000000', '-0.0000000'] | int(1) (truthy) | float(1) (truthy) | error | bool(true) (truthy) | array(2) { [0]=> string(10) "-0.0000000" [1]=> string(10) "-0.0000000" } (truthy) | object(stdClass)#50 (2) { ["0"]=> string(10) "-0.0000000" ["1"]=> string(10) "-0.0000000" } (truthy) |
['-0.0000001', '-0.0000001'] | int(1) (truthy) | float(1) (truthy) | error | bool(true) (truthy) | array(2) { [0]=> string(10) "-0.0000001" [1]=> string(10) "-0.0000001" } (truthy) | object(stdClass)#50 (2) { ["0"]=> string(10) "-0.0000001" ["1"]=> string(10) "-0.0000001" } (truthy) |
['-0.5000000', '-0.5000000'] | int(1) (truthy) | float(1) (truthy) | error | bool(true) (truthy) | array(2) { [0]=> string(10) "-0.5000000" [1]=> string(10) "-0.5000000" } (truthy) | object(stdClass)#50 (2) { ["0"]=> string(10) "-0.5000000" ["1"]=> string(10) "-0.5000000" } (truthy) |
['null', 'null'] | int(1) (truthy) | float(1) (truthy) | error | bool(true) (truthy) | array(2) { [0]=> string(4) "null" [1]=> string(4) "null" } (truthy) | object(stdClass)#50 (2) { ["0"]=> string(4) "null" ["1"]=> string(4) "null" } (truthy) |
new stdClass() | error | error | error | bool(true) (truthy) | array(0) { } (falsy) | object(stdClass)#2 (0) { } (truthy) |
$object->value = 1 | error | error | error | bool(true) (truthy) | array(1) { ["value"]=> int(1) } (truthy) | object(stdClass)#3 (1) { ["value"]=> int(1) } (truthy) |
$object->value = 0 | error | error | error | bool(true) (truthy) | array(1) { ["value"]=> int(0) } (truthy) | object(stdClass)#4 (1) { ["value"]=> int(0) } (truthy) |
$object->value = 00 | error | error | error | bool(true) (truthy) | array(1) { ["value"]=> int(0) } (truthy) | object(stdClass)#5 (1) { ["value"]=> int(0) } (truthy) |
$object->value = -1 | error | error | error | bool(true) (truthy) | array(1) { ["value"]=> int(-1) } (truthy) | object(stdClass)#6 (1) { ["value"]=> int(-1) } (truthy) |
$object->value = -0 | error | error | error | bool(true) (truthy) | array(1) { ["value"]=> int(0) } (truthy) | object(stdClass)#7 (1) { ["value"]=> int(0) } (truthy) |
$object->value = 0x00000 | error | error | error | bool(true) (truthy) | array(1) { ["value"]=> int(0) } (truthy) | object(stdClass)#8 (1) { ["value"]=> int(0) } (truthy) |
$object->value = true | error | error | error | bool(true) (truthy) | array(1) { ["value"]=> bool(true) } (truthy) | object(stdClass)#9 (1) { ["value"]=> bool(true) } (truthy) |
$object->value = false | error | error | error | bool(true) (truthy) | array(1) { ["value"]=> bool(false) } (truthy) | object(stdClass)#10 (1) { ["value"]=> bool(false) } (truthy) |
$object->value = 1.1 | error | error | error | bool(true) (truthy) | array(1) { ["value"]=> float(1.1) } (truthy) | object(stdClass)#11 (1) { ["value"]=> float(1.1) } (truthy) |
$object->value = 1.1111111 | error | error | error | bool(true) (truthy) | array(1) { ["value"]=> float(1.1111111) } (truthy) | object(stdClass)#12 (1) { ["value"]=> float(1.1111111) } (truthy) |
$object->value = 0.0 | error | error | error | bool(true) (truthy) | array(1) { ["value"]=> float(0) } (truthy) | object(stdClass)#13 (1) { ["value"]=> float(0) } (truthy) |
$object->value = 0.0000000 | error | error | error | bool(true) (truthy) | array(1) { ["value"]=> float(0) } (truthy) | object(stdClass)#14 (1) { ["value"]=> float(0) } (truthy) |
$object->value = 0.0000001 | error | error | error | bool(true) (truthy) | array(1) { ["value"]=> float(1.0E-7) } (truthy) | object(stdClass)#15 (1) { ["value"]=> float(1.0E-7) } (truthy) |
$object->value = 0.5000000 | error | error | error | bool(true) (truthy) | array(1) { ["value"]=> float(0.5) } (truthy) | object(stdClass)#16 (1) { ["value"]=> float(0.5) } (truthy) |
$object->value = -1.1 | error | error | error | bool(true) (truthy) | array(1) { ["value"]=> float(-1.1) } (truthy) | object(stdClass)#17 (1) { ["value"]=> float(-1.1) } (truthy) |
$object->value = -1.1111111 | error | error | error | bool(true) (truthy) | array(1) { ["value"]=> float(-1.1111111) } (truthy) | object(stdClass)#18 (1) { ["value"]=> float(-1.1111111) } (truthy) |
$object->value = -0.0 | error | error | error | bool(true) (truthy) | array(1) { ["value"]=> float(-0) } (truthy) | object(stdClass)#19 (1) { ["value"]=> float(-0) } (truthy) |
$object->value = -0.0000000 | error | error | error | bool(true) (truthy) | array(1) { ["value"]=> float(-0) } (truthy) | object(stdClass)#20 (1) { ["value"]=> float(-0) } (truthy) |
$object->value = -0.0000001 | error | error | error | bool(true) (truthy) | array(1) { ["value"]=> float(-1.0E-7) } (truthy) | object(stdClass)#21 (1) { ["value"]=> float(-1.0E-7) } (truthy) |
$object->value = -0.5000000 | error | error | error | bool(true) (truthy) | array(1) { ["value"]=> float(-0.5) } (truthy) | object(stdClass)#22 (1) { ["value"]=> float(-0.5) } (truthy) |
$object->value = 'text' | error | error | error | bool(true) (truthy) | array(1) { ["value"]=> string(4) "text" } (truthy) | object(stdClass)#23 (1) { ["value"]=> string(4) "text" } (truthy) |
$object->value = "\x49\x20\x6c\x6f\x76\x65\x20\x50\x48\x50\x2e" | error | error | error | bool(true) (truthy) | array(1) { ["value"]=> string(11) "I love PHP." } (truthy) | object(stdClass)#24 (1) { ["value"]=> string(11) "I love PHP." } (truthy) |
$object->value = '' | error | error | error | bool(true) (truthy) | array(1) { ["value"]=> string(0) "" } (truthy) | object(stdClass)#25 (1) { ["value"]=> string(0) "" } (truthy) |
$object->value = "\x00" | error | error | error | bool(true) (truthy) | array(1) { ["value"]=> string(1) "" } (truthy) | object(stdClass)#26 (1) { ["value"]=> string(1) "" } (truthy) |
$object->value = ' ' | error | error | error | bool(true) (truthy) | array(1) { ["value"]=> string(1) " " } (truthy) | object(stdClass)#27 (1) { ["value"]=> string(1) " " } (truthy) |
$object->value = ' ' | error | error | error | bool(true) (truthy) | array(1) { ["value"]=> string(3) " " } (truthy) | object(stdClass)#28 (1) { ["value"]=> string(3) " " } (truthy) |
$object->value = '0' | error | error | error | bool(true) (truthy) | array(1) { ["value"]=> string(3) "0" } (truthy) | object(stdClass)#29 (1) { ["value"]=> string(3) "0" } (truthy) |
$object->value = '1' | error | error | error | bool(true) (truthy) | array(1) { ["value"]=> string(1) "1" } (truthy) | object(stdClass)#30 (1) { ["value"]=> string(1) "1" } (truthy) |
$object->value = '0' | error | error | error | bool(true) (truthy) | array(1) { ["value"]=> string(1) "0" } (truthy) | object(stdClass)#31 (1) { ["value"]=> string(1) "0" } (truthy) |
$object->value = '00' | error | error | error | bool(true) (truthy) | array(1) { ["value"]=> string(2) "00" } (truthy) | object(stdClass)#32 (1) { ["value"]=> string(2) "00" } (truthy) |
$object->value = '-1' | error | error | error | bool(true) (truthy) | array(1) { ["value"]=> string(2) "-1" } (truthy) | object(stdClass)#33 (1) { ["value"]=> string(2) "-1" } (truthy) |
$object->value = '-0' | error | error | error | bool(true) (truthy) | array(1) { ["value"]=> string(2) "-0" } (truthy) | object(stdClass)#34 (1) { ["value"]=> string(2) "-0" } (truthy) |
$object->value = 'true' | error | error | error | bool(true) (truthy) | array(1) { ["value"]=> string(4) "true" } (truthy) | object(stdClass)#35 (1) { ["value"]=> string(4) "true" } (truthy) |
$object->value = 'false' | error | error | error | bool(true) (truthy) | array(1) { ["value"]=> string(5) "false" } (truthy) | object(stdClass)#36 (1) { ["value"]=> string(5) "false" } (truthy) |
$object->value = '1.1' | error | error | error | bool(true) (truthy) | array(1) { ["value"]=> string(3) "1.1" } (truthy) | object(stdClass)#37 (1) { ["value"]=> string(3) "1.1" } (truthy) |
$object->value = '1.1111111' | error | error | error | bool(true) (truthy) | array(1) { ["value"]=> string(9) "1.1111111" } (truthy) | object(stdClass)#38 (1) { ["value"]=> string(9) "1.1111111" } (truthy) |
$object->value = '0.0' | error | error | error | bool(true) (truthy) | array(1) { ["value"]=> string(3) "0.0" } (truthy) | object(stdClass)#39 (1) { ["value"]=> string(3) "0.0" } (truthy) |
$object->value = '0.0000000' | error | error | error | bool(true) (truthy) | array(1) { ["value"]=> string(9) "0.0000000" } (truthy) | object(stdClass)#40 (1) { ["value"]=> string(9) "0.0000000" } (truthy) |
$object->value = '0.0000001' | error | error | error | bool(true) (truthy) | array(1) { ["value"]=> string(9) "0.0000001" } (truthy) | object(stdClass)#41 (1) { ["value"]=> string(9) "0.0000001" } (truthy) |
$object->value = '0.5000000' | error | error | error | bool(true) (truthy) | array(1) { ["value"]=> string(9) "0.5000000" } (truthy) | object(stdClass)#42 (1) { ["value"]=> string(9) "0.5000000" } (truthy) |
$object->value = '-1.1' | error | error | error | bool(true) (truthy) | array(1) { ["value"]=> string(4) "-1.1" } (truthy) | object(stdClass)#43 (1) { ["value"]=> string(4) "-1.1" } (truthy) |
$object->value = '-1.1111111' | error | error | error | bool(true) (truthy) | array(1) { ["value"]=> string(10) "-1.1111111" } (truthy) | object(stdClass)#44 (1) { ["value"]=> string(10) "-1.1111111" } (truthy) |
$object->value = '-0.0' | error | error | error | bool(true) (truthy) | array(1) { ["value"]=> string(4) "-0.0" } (truthy) | object(stdClass)#45 (1) { ["value"]=> string(4) "-0.0" } (truthy) |
$object->value = '-0.0000000' | error | error | error | bool(true) (truthy) | array(1) { ["value"]=> string(10) "-0.0000000" } (truthy) | object(stdClass)#46 (1) { ["value"]=> string(10) "-0.0000000" } (truthy) |
$object->value = '-0.0000001' | error | error | error | bool(true) (truthy) | array(1) { ["value"]=> string(10) "-0.0000001" } (truthy) | object(stdClass)#47 (1) { ["value"]=> string(10) "-0.0000001" } (truthy) |
$object->value = '-0.5000000' | error | error | error | bool(true) (truthy) | array(1) { ["value"]=> string(10) "-0.5000000" } (truthy) | object(stdClass)#48 (1) { ["value"]=> string(10) "-0.5000000" } (truthy) |
$object->value = 'null' | error | error | error | bool(true) (truthy) | array(1) { ["value"]=> string(4) "null" } (truthy) | object(stdClass)#49 (1) { ["value"]=> string(4) "null" } (truthy) |
実際にコードを実行した際は以下のようなページが出力されます。画像で見たい方も以下をご参照ください。

結果表の説明
列はキャストに使用した演算子の種類を示しています。
PHP の公式ドキュメントに載っている以下を対象としていますが、 (unset) は PHP7.2 から非推奨とされているので除外しています。
使用可能なキャストを以下に示します:
(int)
- 整数(int) へのキャスト(bool)
- 論理値(bool) へのキャスト(float)
- float へのキャスト(string)
- 文字列(string) へのキャスト(array)
- 配列(array) へのキャスト(object)
- オブジェクト(object) へのキャスト(unset)
- NULL へのキャスト引用元: https://www.php.net/manual/ja/language.types.type-juggling.php#language.types.typecasting
行は前半がスカラー値(数値や文字列のような、単発のデータ)、後半が配列とオブジェクトの複合データ型を扱っています。
スカラー値は以下の 47 種類が対象です。
- 1
- 0
- 00
- -1
- -0
- 0x00000
- true
- false
- 1.1
- 1.1111111
- 0.0
- 0.0000000
- 0.0000001
- 0.5000000
- -1.1
- -1.1111111
- -0.0
- -0.0000000
- -0.0000001
- -0.5000000
- null
- 'text'
- "\x49\x20\x6c\x6f\x76\x65\x20\x50\x48\x50\x2e"
- ''
- "\x00"
- ' '
- ' '
- '0'
- '1'
- '0''00'
- '-1'
- '-0'
- 'true'
- 'false'
- '1.1'
- '1.1111111'
- '0.0'
- '0.0000000'
- '0.0000001'
- '0.5000000'
- '-1.1'
- '-1.1111111'
- '-0.0'
- '-0.0000000'
- '-0.0000001'
- '-0.5000000'
- 'null'
複合データ型は配列の先頭に、
- 空配列
- 配列の中に空配列
- 空配列を包んだ 7 次元配列
が並んだあと、
- 上記スカラー値を 0 番目に持つ配列
- 上記スカラー値を 0 番目と 1 番目に持つ配列
が続きます。
配列の後は stdClass のインスタンスを用いて object 型が並びますが、先頭のみ new stdClass() で生成したての object 、そのあとは value プロパティに上記スカラー値を持つ object が並びます。
各セル左端には検証する値が入っています。
各セル 2 列目からは実際にキャストした値を var_dump した値を載せています。続く括弧内には、それを if 文の条件式部分や参考演算子に用いた場合、真偽どちらと判定されるかを true, false で示しています。
「error」となっている部分は PHP で Warning が発生した部分です。
改めて表を見た所感、気を付けるべきポイント
(int) キャスト
今回初めて知ったのは、'0.0' や '00', '-0' は true として扱われる点です。値としては同じ 0 でも、判定系で特別扱いされるのは '0' が唯一のようですね。
また、float 値を int キャストした結果も地味に初めて知りました。
なんとなく、少数第一位を四捨五入した値になるかと思っていたのですが、少数部分はばっさりと切り捨てられる仕様となっているようです。
これは文字列が相手でも変わらないようです。
また、空配列に対してのキャストが 0 になるのは予想通りですが、空でない配列は内容数にかかわらず 1 となるのも初めて知りました。
もしかしたら count() と同じ結果になるかも、と思ったのですが、基本的に true / false と似たような挙動になるようですね。
(float)キャスト
floart に関しては、元の値が float, もしくは float と解釈できる文字列であれば int キャストと同じ仕様になっているので、特に癖は無いと言えます。
というのも、PHP 内部では文字列型(と、変換の必要がない float 型)以外の値をキャストするときにいったん int 型へ変換した後に float 型にしているからだと思われます。
他の型から float への変換
文字列以外の値については、 まず最初に int に変換された後、 float に変換されます。 詳細は 整数への変換 を参照ください。
引用元: https://www.php.net/manual/ja/language.types.float.php#language.types.float.casting.from-other
(string)キャスト
ほぼほぼ素直に見た目通りの値に変換してくれますが、true は '1' 、false が '' 、 null も '' に変換されるのが直感とは異なる点でしょうか。
しかし、変換後も if 文などの条件式として評価した際も true / false がブレないので、これはこれで正しい仕様だと思います。
特徴的なのが複合データ型が一貫して PHP エラーになる点です。わざわざ string 型にキャストするケースは無いとは思いますが、無意識に使用しないように注意が必要でしょう。
(bool)キャスト
やはり PHP は特異な言語だな、と思わせるのは「'0'」を Boolean にキャストしたときに false となる点ですね。
JavaScript などの言語では文字列の '0' は truthy と判定されます。内容としては 0 でも、空文字ではないので当然な気がしますね。
対して PHP では '0' は false として扱われます。なにか歴史的な香りがしますね。
実務でも意外と遭遇することが多いので覚えておいて損はない、というより必ず覚えておいた方が良い挙動でしょう。
あとほかの言語と違う点は空配列が false と評価されるのも特異と言えるかもしれません。
配列でエラーメッセージ集を返すような関数があったとして、空配列を返したときはエラーなし = 正常系、とするような関数を返り値の型を array に限定した上で作成できるので、地味に便利な仕様だと思います。
対して、 obeject はなんのメンバも持たないインスタンスでも一貫して true と判定されます。
またマニアックなところでは '\x00' 、つまり Null バイト文字列が true になる点が挙げられます。
そのまま HTML として出力されると '' となる文字ですが、厳密には '' ではないので油断していると遭遇するかもしれません。
(array)キャスト
スカラー値を変換したときは一貫して [0] にその値を持った配列が作成されますが、 null だけは特別なようで、空配列が作成されます。
[0 => null] は手動で作成できるものの、サボって (array)null としても期待どおりの値にならないので、値は丁寧に指定してあげるのが良さそうです。
(object)キャスト
ほぼほぼ使用しないので知らなかったのですが、スカラー値を object でキャストすると scalar というプロパティにその値がセットされた状態で stdClass インスタンスが生成されるようです。
オブジェクトへの変換
(略)
上記以外の値の場合には、
scalar
という名前のメンバ変数が値を格納します。引用元: https://www.php.net/manual/ja/language.types.object.php#language.types.object.casting
それ以外はだいたい array キャストと同様で、やはり null を相手にしたときは空の stdClass が生成されるようです。
結果表出力 PHP コード
結果表については上記の通りですが、PHP のバージョンや設定、環境でこれらは変わる可能性があるので、実際に業務へ役立てるには実際の環境で確かめるのが一番です。
結果表を確認する場合は以下のコードをサーバーにアップロードしてブラウザで表示してみてください。
PHP バージョンなども表示されるので、いざ使用する場合はパブリックな部分に置かない方がよいでしょう。
<?php
//Warning を catch で拾えるようにする
set_error_handler(function($errno, $errstr, $errfile, $errline) {
throw new ErrorException($errstr, $errno, 0, $errfile, $errline);
});
//表の各セルに記載する html を出力用
function castResult($value, $cast) {
ob_start();
try {
switch ($cast) {
case 'int':
var_dump((int)$value);
echo (int)$value ? '<span style="color: blue;">(truthy)</span>' : '<span style="color: red;">(falsy)</span>';
break;
case 'bool':
var_dump((bool)$value);
echo (bool)$value ? '<span style="color: blue;">(truthy)</span>' : '<span style="color: red;">(falsy)</span>';
break;
case 'float':
var_dump((float)$value);
echo (float)$value ? '<span style="color: blue;">(truthy)</span>' : '<span style="color: red;">(falsy)</span>';
break;
case 'string':
var_dump((string)$value);
echo (string)$value ? '<span style="color: blue;">(truthy)</span>' : '<span style="color: red;">(falsy)</span>';
break;
case 'array':
var_dump((array)$value);
echo (array)$value ? '<span style="color: blue;">(truthy)</span>' : '<span style="color: red;">(falsy)</span>';
break;
case 'object':
var_dump((object)$value);
echo (object)$value ? '<span style="color: blue;">(truthy)</span>' : '<span style="color: red;">(falsy)</span>';
break;
}
}
catch (Throwable $exception) {
echo '<strong title="'.$exception->getMessage().'" style="color: purple"> error</strong>';
}
return ob_get_clean();
};
//1 段目: int のバリエーション
//2 段目: true と false
//2 段目: float のバリエーション
//4 段目: null
//5 段目: 適当な文字列、16進数表記、空文字、Null バイト、半角スペース、全角スペース、全角0(ゼロ)
//6 段目: 1 ~ 4 段の内容を文字列にしたもの
//7 段目: 空配列、配列の中に空配列、空配列を包んだ 7 次元配列
//8 段目: 1 ~ 6 段の内容を 0 番目に持つ配列
//8 段目: 1 ~ 6 段の内容を 0, 1 番目に持つ配列
//9 段目: インスタンス化した直後の stdClass
$challengers = [
['value' => 1, 'label' => '1'], ['value' => 0, 'label' => '0'], ['value' => 00, 'label' => '00'], ['value' => -1, 'label' => '-1'], ['value' => -0, 'label' => '-0'], ['value' => 0x00000, 'label' => '0x00000'],
['value' => true, 'label' => 'true'], ['value' => false, 'label' => 'false'],
['value' => 1.1, 'label' => '1.1'], ['value' => 1.1111111, 'label' => '1.1111111'], ['value' => 0.0, 'label' => '0.0'], ['value' => 0.0000000, 'label' => '0.0000000'], ['value' => 0.0000001, 'label' => '0.0000001'], ['value' => 0.5000000, 'label' => '0.5000000'], ['value' => -1.1, 'label' => '-1.1'], ['value' => -1.1111111, 'label' => '-1.1111111'], ['value' => -0.0, 'label' => '-0.0'], ['value' => -0.0000000, 'label' => '-0.0000000'], ['value' => -0.0000001, 'label' => '-0.0000001'], ['value' => -0.5000000, 'label' => '-0.5000000'],
['value' => null, 'label' => 'null'],
['value' => 'text', 'label' => "'text'"], ['value' =>"\x49\x20\x6c\x6f\x76\x65\x20\x50\x48\x50\x2e", 'label' => '"\x49\x20\x6c\x6f\x76\x65\x20\x50\x48\x50\x2e"'], ['value' => '', 'label' => "''"], ['value' => "\x00", 'label' => '"\x00"'], ['value' => ' ', 'label' => "' '"], ['value' => ' ', 'label' => "' '"], ['value' => '0', 'label' => "'0'"],
['value' => '1', 'label' => "'1'"], ['value' => '0', 'label' => "'0'"],['value' => '00', 'label' => "'00'"], ['value' => '-1', 'label' => "'-1'"], ['value' => '-0', 'label' => "'-0'"], ['value' => 'true', 'label' => "'true'"], ['value' => 'false', 'label' => "'false'"], ['value' => '1.1', 'label' => "'1.1'"], ['value' => '1.1111111', 'label' => "'1.1111111'"], ['value' => '0.0', 'label' => "'0.0'"], ['value' => '0.0000000', 'label' => "'0.0000000'"], ['value' => '0.0000001', 'label' => "'0.0000001'"], ['value' => '0.5000000', 'label' => "'0.5000000'"], ['value' => '-1.1', 'label' => "'-1.1'"], ['value' => '-1.1111111', 'label' => "'-1.1111111'"], ['value' => '-0.0', 'label' => "'-0.0'"], ['value' => '-0.0000000', 'label' => "'-0.0000000'"], ['value' => '-0.0000001', 'label' => "'-0.0000001'"], ['value' => '-0.5000000', 'label' => "'-0.5000000'"], ['value' => 'null', 'label' => "'null'"],
['value' => [], 'label' => '[]'], ['value' => [[]], 'label' => '[[]]'], ['value' => [[[[[[[]]]]]]], 'label' => '[[[[[[[]]]]]]]'],
['value' => [1], 'label' => '[1]'], ['value' => [0], 'label' => '[0]'], ['value' => [00], 'label' => '[00]'], ['value' => [-1], 'label' => '[-1]'], ['value' => [-0], 'label' => '[-0]'], ['value' => [0x00000], 'label' => '[0x00000]'], ['value' => [true], 'label' => '[true]'], ['value' => [false], 'label' => '[false]'], ['value' => [1.1], 'label' => '[1.1]'], ['value' => [1.1111111], 'label' => '[1.1111111]'], ['value' => [0.0], 'label' => '[0.0]'], ['value' => [0.0000000], 'label' => '[0.0000000]'], ['value' => [0.0000001], 'label' => '[0.0000001]'], ['value' => [0.5000000], 'label' => '[0.5000000]'], ['value' => [-1.1], 'label' => '[-1.1]'], ['value' => [-1.1111111], 'label' => '[-1.1111111]'], ['value' => [-0.0], 'label' => '[-0.0]'], ['value' => [-0.0000000], 'label' => '[-0.0000000]'], ['value' => [-0.0000001], 'label' => '[-0.0000001]'], ['value' => [-0.5000000], 'label' => '[-0.5000000]'], ['value' => [null], 'label' => '[null]'], ['value' => ['text'], 'label' => "['text']"], ['value' => ["\x49\x20\x6c\x6f\x76\x65\x20\x50\x48\x50\x2e"], 'label' => '["\x49\x20\x6c\x6f\x76\x65\x20\x50\x48\x50\x2e"]'], ['value' => [''], 'label' => "['']"], ['value' => ["\x00"], 'label' => '["\x00"]'], ['value' => [' '], 'label' => "[' ']"], ['value' => [' '], 'label' => "[' ']"], ['value' => ['0'], 'label' => "['0']"], ['value' => ['1'], 'label' => "['1']"], ['value' => ['0'], 'label' => "['0']"], ['value' => ['00'], 'label' => "['00']"], ['value' => ['-1'], 'label' => "['-1']"], ['value' => ['-0'], 'label' => "['-0']"], ['value' => ['true'], 'label' => "['true']"], ['value' => ['false'], 'label' => "['false']"], ['value' => ['1.1'], 'label' => "['1.1']"], ['value' => ['1.1111111'], 'label' => "['1.1111111']"], ['value' => ['0.0'], 'label' => "['0.0']"], ['value' => ['0.0000000'], 'label' => "['0.0000000']"], ['value' => ['0.0000001'], 'label' => "['0.0000001']"], ['value' => ['0.5000000'], 'label' => "['0.5000000']"], ['value' => ['-1.1'], 'label' => "['-1.1']"], ['value' => ['-1.1111111'], 'label' => "['-1.1111111']"], ['value' => ['-0.0'], 'label' => "['-0.0']"], ['value' => ['-0.0000000'], 'label' => "['-0.0000000']"], ['value' => ['-0.0000001'], 'label' => "['-0.0000001']"], ['value' => ['-0.5000000'], 'label' => "['-0.5000000']"], ['value' => ['null'], 'label' => "['null']"],
['value' => [1, 1], 'label' => "[1, 1]"], ['value' => [0, 0], 'label' => "[0, 0]"], ['value' => [00, 00], 'label' => "[00, 00]"], ['value' => [-1, -1], 'label' => "[-1, -1]"], ['value' => [-0, -0], 'label' => "[-0, -0]"], ['value' => [0x00000, 0x00000], 'label' => "[0x00000, 0x00000]"], ['value' => [true, true], 'label' => "[true, true]"], ['value' => [false, false], 'label' => "[false, false]"], ['value' => [1.1, 1.1], 'label' => "[1.1, 1.1]"], ['value' => [1.1111111, 1.1111111], 'label' => "[1.1111111, 1.1111111]"], ['value' => [0.0, 0.0], 'label' => "[0.0, 0.0]"], ['value' => [0.0000000, 0.0000000], 'label' => "[0.0000000, 0.0000000]"], ['value' => [0.0000001, 0.0000001], 'label' => "[0.0000001, 0.0000001]"], ['value' => [0.5000000, 0.5000000], 'label' => "[0.5000000, 0.5000000]"], ['value' => [-1.1, -1.1], 'label' => "[-1.1, -1.1]"], ['value' => [-1.1111111, -1.1111111], 'label' => "[-1.1111111, -1.1111111]"], ['value' => [-0.0, -0.0], 'label' => "[-0.0, -0.0]"], ['value' => [-0.0000000, -0.0000000], 'label' => "[-0.0000000, -0.0000000]"], ['value' => [-0.0000001, -0.0000001], 'label' => "[-0.0000001, -0.0000001]"], ['value' => [-0.5000000, -0.5000000], 'label' => "[-0.5000000, -0.5000000]"], ['value' => [null, null], 'label' => "[null, null]"], ['value' => ['text', 'text'], 'label' => "['text', 'text']"], ['value' => ["\x49\x20\x6c\x6f\x76\x65\x20\x50\x48\x50\x2e", "\x49\x20\x6c\x6f\x76\x65\x20\x50\x48\x50\x2e"], 'label' => '["\x49\x20\x6c\x6f\x76\x65\x20\x50\x48\x50\x2e", "\x49\x20\x6c\x6f\x76\x65\x20\x50\x48\x50\x2e"]'], ['value' => ['', ''], 'label' => "['', '']"], ['value' => ["\x00", "\x00"], 'label' => '["\x00", "\x00"]'], ['value' => [' ', ' '], 'label' => "[' ', ' ']"], ['value' => [' ', ' '], 'label' => "[' ', ' ']"], ['value' => ['0', '0'], 'label' => "['0', '0']"], ['value' => ['1', '1'], 'label' => "['1', '1']"], ['value' => ['0', '0'], 'label' => "['0', '0']"], ['value' => ['00', '00'], 'label' => "['00', '00']"], ['value' => ['-1', '-1'], 'label' => "['-1', '-1']"], ['value' => ['-0', '-0'], 'label' => "['-0', '-0']"], ['value' => ['true', 'true'], 'label' => "['true', 'true']"], ['value' => ['false', 'false'], 'label' => "['false', 'false']"], ['value' => ['1.1', '1.1'], 'label' => "['1.1', '1.1']"], ['value' => ['1.1111111', '1.1111111'], 'label' => "['1.1111111', '1.1111111']"], ['value' => ['0.0'], 'label' => "['0.0', '0.0']"], ['value' => ['0.0000000', '0.0000000'], 'label' => "['0.0000000', '0.0000000']"], ['value' => ['0.0000001', '0.0000001'], 'label' => "['0.0000001', '0.0000001']"], ['value' => ['0.5000000', '0.5000000'], 'label' => "['0.5000000', '0.5000000']"], ['value' => ['-1.1', '-1.1'], 'label' => "['-1.1', '-1.1']"], ['value' => ['-1.1111111', '-1.1111111'], 'label' => "['-1.1111111', '-1.1111111']"], ['value' => ['-0.0', '-0.0'], 'label' => "['-0.0', '-0.0']"], ['value' => ['-0.0000000', '-0.0000000'], 'label' => "['-0.0000000', '-0.0000000']"], ['value' => ['-0.0000001', '-0.0000001'], 'label' => "['-0.0000001', '-0.0000001']"], ['value' => ['-0.5000000', '-0.5000000'], 'label' => "['-0.5000000', '-0.5000000']"], ['value' => ['null', 'null'], 'label' => "['null', 'null']"],
['value' => new stdClass(), 'label' => 'new stdClass()']
];
//上記配列中、スラカー値のみを選別して、それを value プロパティに持つ stdClass を追加する
$objects = [];
foreach ($challengers as $challenger)
{
if ( ! is_scalar($challenger['value']))
{
continue;
}
$object = new stdClass();
$object->value = $challenger['value'];
$objects[] = ['value' => $object, 'label' => '$object->value = '.$challenger['label']];
}
$challengers = array_merge($challengers, $objects);
//キャスト演算子一覧
$casts = ['int', 'float', 'string', 'bool', 'array', 'object'];
?>
<!doctype html>
<html lang="ja">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<meta name="format-detection" content="telephone=no">
<title>PHP キャスト表</title>
<style>
table {
font-size: 12px;
border: #aaa solid 1px;
margin: 5px;
border-collapse: collapse;
table-layout: fixed;
text-align: center;
}
tr:nth-child(even) {
background-color: rgba(200, 200, 200, .5);
}
th, td {
border: #aaa solid 1px;
padding: 5px;
min-width: 100px;
}
td:first-child {
font-weight: 700;
}
</style>
</head>
<body>
<h1>PHP cast results table(PHP Version: <?php echo phpversion(); ?>)</h1>
<table>
<thead>
<tr>
<th> </th>
<?php foreach ($casts as $cast): ?>
<th>(<?php echo $cast; ?>)</th>
<?php endforeach; ?>
</tr>
</thead>
<tbody>
<?php foreach ($challengers as $challenger): ?>
<tr>
<td><?php echo $challenger['label']; ?></td>
<?php foreach ($casts as $cast): ?>
<td><?php echo castResult($challenger['value'], $cast); ?></td>
<?php endforeach; ?>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</body>
</html>
まとめ
PHP は動的型付けの言語ですが、では開発者が全然型を気にしないで開発ができるかというとそんなことはありません。
関数やメソッドを介して値が受け渡される場合や、二つの値の比較など、型が合っている前提でないと思わぬ挙動となってしまう処理は多々あります。
そんなときに便利かつ、低コストでパフォーマンスが出るのが PHP の組み込みキャスト演算子です。
特に PHP を学び始めだと理解が面倒な部分でもありますが、使いこなしていくとそのうち挙動が頭に染みついてくるので、是非うまくつかいこなしてみてください。
プログラマー/N.Go