Bug #62874 [Com]: getDefaultValue() fails
| From: | karsten at typo3 dot org | Date: | Tue, 21 Aug 2012 07:45:41 +0000 |
| Subject: | Bug #62874 [Com]: getDefaultValue() fails | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-172754@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=62874&edit=1
ID: 62874
Comment by: karsten at typo3 dot org
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:
Indeed, my test script runs with the expected output on php5.3-latest.
And the output of 5.3 and 5.4 differ when it comes to isDefaultValueAvailable() -
see https://gist.github.com/724fbc1e29fb7b0bad59
- failed because on 5.4.0 the bug
#62715 did still exist.
Previous Comments:
------------------------------------------------------------------------
[2012-08-21 05:42:51] laruence@php.net
seems it already be fixed. please try with the 5.3-master snapshot
------------------------------------------------------------------------
[2012-08-21 05:41:58] laruence@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] laruence@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