Last active
April 22, 2016 10:12
-
-
Save y-uti/e9a686c08d7abe8b97c3e4dc63099bf5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function test($init, $key = 'a') | |
{ | |
$var = $init; | |
$var[$key] = 1; | |
echo var_export($init, true), ': ', is_array($var) ? 1 : 0, "\n"; | |
} | |
test(null); // OK | |
test(false); // OK | |
test(true); // PHP Warning: Cannot use a scalar value as an array in ... | |
test(0); // PHP Warning: Cannot use a scalar value as an array in ... | |
test(1); // PHP Warning: Cannot use a scalar value as an array in ... | |
test(''); // OK | |
test('abc'); // PHP Warning: Illegal string offset 'a' in ... | |
test(new stdClass()); // PHP Fatal error: Uncaught Error: Cannot use object of type stdClass as array in ... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
配列ではない変数に添字を指定して代入したときの挙動