DEVSENSE / Phalanger

PHP 5.4 compiler for .NET/Mono frameworks. Predecessor to the opensource PeachPie project (www.peachpie.io).
http://v4.php-compiler.net/
Apache License 2.0
381 stars 92 forks source link

Incompatible behavior of func_get_args() in a closure #60

Open weirdan opened 8 years ago

weirdan commented 8 years ago

In Phalanger (1d64ededa2eaa) func_get_args() returns use()'d variables in addition to real arguments, while php and hhvm only return closure's arguments:

$ cat qq.php
<?php
class QQ
{
    public static function main()
    {
        $q = 123;
        $f = function($param) use($q) {
            var_dump(func_get_args());
        };
        $f("asd");
    }
}

$ Deployment/Debug/phpc.exe qq.php /reference:/usr/lib/mono/gac/PhpNetCore/4.0.0.0__0a8e8c4c76728c71/PhpNetCore.dll /reference:/usr/lib/mono/gac/PhpNetClassLibrary/4.0.0.0__4af37afe3cde05fb/PhpNetClassLibrary.dll /out:qq.exe /target:exe /encoding:UTF-8 /pure+ /entrypoint:qq.php /debug+
Phalanger - the PHP Language Compiler - version 4.0
for Microsoft (R) .NET Framework version 4.0
Arguments:
qq.php
/reference:/usr/lib/mono/gac/PhpNetCore/4.0.0.0__0a8e8c4c76728c71/PhpNetCore.dll
/reference:/usr/lib/mono/gac/PhpNetClassLibrary/4.0.0.0__4af37afe3cde05fb/PhpNetClassLibrary.dll
/out:qq.exe
/target:exe
/encoding:UTF-8
/pure+
/entrypoint:qq.php
/debug+

Encoding  cannot be loaded.
fileEncoding=""

Loaded libraries:
PhpNetCore, Version=4.0.0.0, Culture=neutral, PublicKeyToken=0a8e8c4c76728c71
Base Library (PhpNetClassLibrary)

Performing compilation ...

Statistics:
Compiled in 0:00.280.
AST: LibraryFunctionCalls = 2, UnknownFunctionCalls = 0

Build complete -- 0 errors, 0 warnings.

$ ./qq.exe
Encoding  cannot be loaded.
fileEncoding=""

array(2) {
  [0]=>
  int(123)
  [1]=>
  string(3) "asd"
}

$ php -r 'echo phpversion() . PHP_EOL; require "qq.php"; QQ::main();'
5.6.16-2
array(1) {
  [0] =>
  string(3) "asd"
}

See https://3v4l.org/GoUiU for more environments (various php & hhvm versions).