From: pmjones88 at gmail dot com Operating system: Mac OS X 10.8.4 PHP version: 5.4.17 Package: Reflection related Bug Type: Bug Bug description:ReflectionParameter::isDefaultValueAvailable inconsistent for Closure
Description: ------------ When calling ReflectionParameter::isDefaultValueAvailable() on Closure::__invoke() as an object method, it returns the incorrect value. However, when calling it on a closure as a function, it returns the correct value. Examples below. Test script: --------------- <?php /** * the expected behavior from an object */ class Foo { public function __invoke($baz = 'qux') { return $baz; } } $object = new Foo; var_dump(is_object($object)); // true, so PHP thinks it's an object $method = new ReflectionMethod($object, '__invoke'); // object method exists $params = $method->getParameters(); var_dump($params[0]->isDefaultValueAvailable()); // true /** * now test a closure */ // note the default value $closure = function ($baz = 'qux') { return $baz; }; // treat it as an object: available = false (unexpected) var_dump(is_object($closure)); // true, so PHP thinks it's an object $method = new ReflectionMethod($closure, '__invoke'); // object method exists $params = $method->getParameters(); var_dump($params[0]->isDefaultValueAvailable()); // false // treat it as a function: available = true (expected) $func = new ReflectionFunction($closure); $params = $func->getParameters(); var_dump($params[0]->isDefaultValueAvailable()); // true Expected result: ---------------- I figured, since PHP seems to think the Closure is an object, that one could get a correct isDefaultValueAvailable() from reflecting on __invoke() as an object method (in this case, boolean TRUE). Actual result: -------------- It returns boolean FALSE when reflecting on Closure::__invoke() as an object method. -- Edit bug report at https://bugs.php.net/bug.php?id=65432&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=65432&r=trysnapshot54 Try a snapshot (PHP 5.3): https://bugs.php.net/fix.php?id=65432&r=trysnapshot53 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=65432&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=65432&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=65432&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=65432&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=65432&r=needscript Try newer version: https://bugs.php.net/fix.php?id=65432&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=65432&r=support Expected behavior: https://bugs.php.net/fix.php?id=65432&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=65432&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=65432&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=65432&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=65432&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=65432&r=dst IIS Stability: https://bugs.php.net/fix.php?id=65432&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=65432&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=65432&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=65432&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=65432&r=mysqlcfg