Skip to content

Latest commit

 

History

History
54 lines (39 loc) · 898 Bytes

readme.md

File metadata and controls

54 lines (39 loc) · 898 Bytes

With this extension you can use closures without use statement

Build Status

$x = 100;

$foo = function() {
    return $x;
};

echo $foo(), PHP_EOL;

Limitations

  • if local variable is created by passing by reference
$foo = function () {
    // workaround: $matches = [];
    preg_match('/^test$/', 'test', $matches); // Undefined variable $matches
    return $matches[0] ?? '';
};

echo $foo(), PHP_EOL;
  • extract, eval and other ways to implicitly create variable
$foo = function() {
    // workaround: $x = 0;
    eval('$x = 100;'); Undefined variable $x
    return $x;
};

echo $foo(), PHP_EOL;

Installation

phpize
./configure
make
make install

Testing

make test