Re:Announcing a specification for PHP
by wvenable on Thursday July 31, 2014 @11:26AM
(#8114644)
A lot of languages have ways of calling functions and methods by string names -- PHP just makes it very easy and the design is actually really clean.
[ Parent
| on HN ]
Re:Announcing a specification for PHP
by chriswarbo on Friday August 01, 2014 @08:27AM
(#8119419)
> PHP just makes it very easy and the design is actually really clean.
Very little about PHP's treatment of functions is easy or clean.
function foo() { echo "Hello world"; }
$w = 'foo';
echo $w; // foo
$w(); // Hello world
'foo'(); // PHP Parse error: syntax error, unexpected '('
function bar() { return 'foo'; }
$x = bar();
echo $x; // foo
$x(); // Hello world
bar()(); // PHP Parse error: syntax error, unexpected '('
$o = new stdClass;
$o->baz = 'foo';
$y = $o->baz;
echo $y; // foo
$y(); // Hello world
$o->baz(); // PHP Fatal error: Call to undefined method stdClass::baz()
Heck, PHP doesn't even recognise function-call syntax applied to a function! $z = function() {
echo "Hello world";
};
$z(); // Hello world
(function() {
echo "Hello world";
})(); // PHP Parse error: syntax error, unexpected '('When this[1] RFC goes through most of those issues will be resolved. Even without them, ignoring edge cases ('foo'() isn't useful), it's still quite reasonable. The RFC linked above just improves on the design, it doesn't change it.