3 ms·
$foo = []; $foo[$userSuppliedString] = 'foo'; foreach(array_keys($foo) as $userSuppliedString) { if (! is_string($userSuppliedString)) {
by mappu 13y ago
$foo = [];
$foo[$userSuppliedString] = 'foo';
foreach(array_keys($foo) as $userSuppliedString) {
if (! is_string($userSuppliedString)) {
die("I understand all the reasons for this behaviour, but it violates the principle of least astonishment");
}
}
Supply a string. Works fine? Try running with a string that looks numeric.
I use PHP every day, it's a great language for many things including teaching programming. Every language has its quirks and i don't really think PHP's quirks are worse than others.
"The Tao gave birth to machine language. Machine language gave birth to the assembler. The assembler gave birth to the compiler. Now there are ten thousand languages. Each language has its purpose, however humble. Each language expresses the Yin and Yang of software. Each language has its place within the Tao - but do not program in COBOL if you can avoid it."