points by chriswarbo 11 years ago

> 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 '('
wvenable 11 years ago

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.

[1] https://wiki.php.net/rfc/uniform_variable_syntax