Edit report at https://bugs.php.net/bug.php?id=62988&edit=1
ID: 62988
Comment by: juzna dot cz at gmail dot com
Reported by: juzna dot cz at gmail dot com
Summary: ReflectionParameter::getDefaultValue throws when it
shouldn't
Status: Feedback
Type: Bug
Package: Reflection related
Operating System: Ubuntu
PHP Version: 5.3.16
Block user comment: N
Private report: N
New Comment:
Thanks, works as expected.
Previous Comments:
------------------------------------------------------------------------
[2012-09-01 10:41:47] [email protected]
Please try using this snapshot:
http://snaps.php.net/php5.3-latest.tar.gz
For Windows:
http://windows.php.net/snapshots/
------------------------------------------------------------------------
[2012-09-01 08:44:30] juzna dot cz at gmail dot com
Description:
------------
In case an optional parameter is followed by NOT optional parameter, reflection
behaves incorrectly.
On that particular instance of ReflectionParameter, isDefaultValueAvailable()
returns TRUE but getDefaultValue then throws.
I tested it on 5.3.11 where it worked (but where it threw away the default
value), on 5.3.16 it throws.
Test script:
---------------
class Foo {
function bar($a = NULL, $b) { }
}
$rm = new ReflectionMethod('Foo', 'bar');
foreach ($rm->getParameters() as $param) {
echo $param->getName(), "\n";
var_dump($param->isDefaultValueAvailable());
if ($param->isDefaultValueAvailable())
var_dump($param->getDefaultValue());
}
Expected result:
----------------
a
bool(true)
NULL
b
bool(false)
Actual result:
--------------
// on 5.3.16
a
bool(true)
Fatal error: Uncaught exception 'ReflectionException' with message 'Parameter
is
not optional'
// on 5.3.11
a
bool(false)
b
bool(false)
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=62988&edit=1