Edit report at https://bugs.php.net/bug.php?id=62874&edit=1
ID: 62874 Updated by: larue...@php.net Reported by: karsten at typo3 dot org Summary: getDefaultValue() fails Status: Open Type: Bug Package: Reflection related Operating System: OS X PHP Version: 5.3.16 Block user comment: N Private report: N New Comment: hmm, I fixed a similar bug before, I still think it's a wrong usage.. however I will fix this later. Previous Comments: ------------------------------------------------------------------------ [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