Skip to content

Instantly share code, notes, and snippets.

@voituk
Created March 3, 2012 11:25
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save voituk/1965613 to your computer and use it in GitHub Desktop.
Save voituk/1965613 to your computer and use it in GitHub Desktop.
PHP 5.4 WTF?
<?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