引入AST的一个例子

<?php

class C
{
    public $fn;

    public function __construct(callable $fn)
    {
        $this->fn = $fn;
    }

    public function invokeFn()
    {
        ($this->fn)();

        // in php5
        // $fn = $this->fn; $fn();
        // or 
        // call_user_func($this->fn);
    }
}

(new C(function() { echo "HELLO"; }))->invokeFn();
Output for hhvm-3.12.14 - 3.18.1, 7.0.0 - 7.1.3
HELLO
Output for 5.6.0 - 5.6.30
Parse error: syntax error, unexpected '(' in /in/Xcj38 on line 14

Process exited with code 255.

results matching ""

    No results matching ""