Created
March 3, 2012 11:25
-
-
Save voituk/1965613 to your computer and use it in GitHub Desktop.
PHP 5.4 WTF?
This file contains 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 vvv() { | |
return [10 => 1111, 20 => 222222, 30, 40]; | |
} | |
// Works OK | |
var_dump( vvv()[10] ); | |
function ccc() { | |
return function() { | |
return time(); | |
}; // <------------ this is ridiculous | |
}; // <-------------- ... this too | |
// Works OK! | |
print_r(ccc() ); // -> Closure Object () | |
// Works OK! - call __invoke in returned Closure | |
print_r(ccc()->__invoke()); | |
// PHP Parse error: syntax error, unexpected '(' in /home/vadim/11.php | |
print_r(ccc()()); // No short call support! | |
$x = function() { | |
print_r(func_get_args()); | |
}; | |
// Works OK | |
$www = $x->bindTo(new StdClass()); | |
print_r($www); // -> Closure Object () | |
print_r($www->__invoke("Hello", "Moto")); // Call method on it | |
// PHP Parse error: syntax error, unexpected '->' (T_OBJECT_OPERATOR) in /home/vadim/11.php | |
print_r( ($x->bindTo(new StdClass()))->__invoke("Hello", "Moto") ); | |
// WTF? | |
// PHP Parse error: syntax error, unexpected '(' in /home/vadim/11.php | |
//// print_r( ($x->bindTo(new StdClass()))("Hello", "Moto") ); | |
// The same WTF? | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment