Edit report at https://bugs.php.net/bug.php?id=62874&edit=1
ID: 62874 Comment by: larue...@php.net Reported by: karsten at typo3 dot org Summary: getDefaultValue() fails Status: Feedback Type: Bug Package: Reflection related Operating System: OS X PHP Version: 5.3.16 Assigned To: laruence Block user comment: N Private report: N New Comment: seems it already be fixed. please try with the 5.3-master snapshot Previous Comments: ------------------------------------------------------------------------ [2012-08-21 05:41:58] larue...@php.net Please try using this snapshot: http://snaps.php.net/php5.3-latest.tar.gz For Windows: http://windows.php.net/snapshots/ ------------------------------------------------------------------------ [2012-08-20 14:27:41] karsten at typo3 dot org You mean https://bugs.php.net/62715 - it brought me on track. I have a report for my test script ran on 5.4 that results in https://gist.github.com/467127b13f987b1633d9, so it seems isDefaultValueAvailable() returns false there⦠------------------------------------------------------------------------ [2012-08-20 14:04:10] larue...@php.net hmm, I fixed a similar bug before, I still think it's a wrong usage.. however I will fix this later. ------------------------------------------------------------------------ [2012-08-20 13:22:42] karsten at typo3 dot org Description: ------------ If isDefaultValueAvailable() returns TRUE I expect to be able to call getDefaultValue() Test script: --------------- <?php class a { protected function test(array $a = NULL, $b, array $c = NULL) {} } $class = new ReflectionClass('a'); foreach ($class->getMethods() as $method) { foreach ($method->getParameters() as $p) { echo $p->getName() . "\n"; echo " isDefaultValueAvailable: " . var_export($p->isDefaultValueAvailable(), true) . "\n"; if ($p->isDefaultValueAvailable()) { echo " default value: " . var_export($p->getDefaultValue(), true) . "\n"; } echo " isOptional: " . var_export($p->isOptional(), true) . "\n"; echo " allowsNull: " . var_export($p->allowsNull(), true) . "\n"; echo "\n"; } } ?> Expected result: ---------------- a isDefaultValueAvailable: true default value: NULL isOptional: false allowsNull: true b isDefaultValueAvailable: false isOptional: false allowsNull: true c isDefaultValueAvailable: true default value: NULL isOptional: true allowsNull: true Actual result: -------------- a isDefaultValueAvailable: true Fatal error: Uncaught exception 'ReflectionException' with message 'Parameter is not optional' in test.php on line 12 ReflectionException: Parameter is not optional in test.php on line 12 Call Stack: 0.0010 646632 1. {main}() test.php:0 0.0011 651128 2. ReflectionParameter->getDefaultValue() test.php:12 ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=62874&edit=1