Skip to content

vajexal/php-ext-implicit-closures

Repository files navigation

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

About

php extension that eliminates use statements in closures

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published