From:             karsten at typo3 dot org
Operating system: OS X
PHP version:      5.3.16
Package:          Reflection related
Bug Type:         Bug
Bug description:getDefaultValue() fails

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 bug report at https://bugs.php.net/bug.php?id=62874&edit=1
-- 
Try a snapshot (PHP 5.4):            
https://bugs.php.net/fix.php?id=62874&r=trysnapshot54
Try a snapshot (PHP 5.3):            
https://bugs.php.net/fix.php?id=62874&r=trysnapshot53
Try a snapshot (trunk):              
https://bugs.php.net/fix.php?id=62874&r=trysnapshottrunk
Fixed in SVN:                        
https://bugs.php.net/fix.php?id=62874&r=fixed
Fixed in SVN and need be documented: 
https://bugs.php.net/fix.php?id=62874&r=needdocs
Fixed in release:                    
https://bugs.php.net/fix.php?id=62874&r=alreadyfixed
Need backtrace:                      
https://bugs.php.net/fix.php?id=62874&r=needtrace
Need Reproduce Script:               
https://bugs.php.net/fix.php?id=62874&r=needscript
Try newer version:                   
https://bugs.php.net/fix.php?id=62874&r=oldversion
Not developer issue:                 
https://bugs.php.net/fix.php?id=62874&r=support
Expected behavior:                   
https://bugs.php.net/fix.php?id=62874&r=notwrong
Not enough info:                     
https://bugs.php.net/fix.php?id=62874&r=notenoughinfo
Submitted twice:                     
https://bugs.php.net/fix.php?id=62874&r=submittedtwice
register_globals:                    
https://bugs.php.net/fix.php?id=62874&r=globals
PHP 4 support discontinued:          
https://bugs.php.net/fix.php?id=62874&r=php4
Daylight Savings:                    https://bugs.php.net/fix.php?id=62874&r=dst
IIS Stability:                       
https://bugs.php.net/fix.php?id=62874&r=isapi
Install GNU Sed:                     
https://bugs.php.net/fix.php?id=62874&r=gnused
Floating point limitations:          
https://bugs.php.net/fix.php?id=62874&r=float
No Zend Extensions:                  
https://bugs.php.net/fix.php?id=62874&r=nozend
MySQL Configuration Error:           
https://bugs.php.net/fix.php?id=62874&r=mysqlcfg

Reply via email to