Been a while. Have a simple one – what does this print?
$arr[null] = "Null string"; $arr[false] = "False string"; $arr[0] = "Zero string"; print_r($arr);
Been a while. Have a simple one – what does this print?
$arr[null] = "Null string"; $arr[false] = "False string"; $arr[0] = "Zero string"; print_r($arr);
Early on in PHP’s life, its type system contained only strings, ints, reals, arrays, “resources,” and null. A number of features have been bodged in on top of this minimal system without really extending it. “Function pointer” functionality was one of the first.
It’s Monday, and I’m sick, so you get some low-hanging fruit today. The following snippet produces a syntax error in PHP:
1 2 3 4 5 6 7 | < ?php function monolithic_dimensions() { return array(1, 4, 9); } print monolithic_dimensions()[0]; // syntax error, unexpected '[' ?> |
Most modern languages have a construct that allows code to run at the end of a block regardless of how flow leaves a block. This allows code to reliably close resources, perform rollbacks, and otherwise maintain invariants relatively easily, even in the presence of exceptions.