An interesting bug in ReflectionParameter object in PHP 5.2.1

I came across an interesting bug last night. I searched for the reference and found that Sebastian Bergman reported quite similar bug in 11 Jun 2005 (Bug # 33312) which is currently marked as closed. I tested that bug reported by Sebastian and well, its fixed.

But there is still the following bug alive in ReflectionParameter object, I tested it against the PHP version 5.2.1 . So what is this bug? The reflection parameter cannot retrieve the default value of a parameter if the next parameter has no default value. PHP simply omits all the variables before that variable and return only values after that variable (I am sorry for my poor english). To regenerate the bug, you can execute the following script

[sourcecode language=”php”]
<?
class TestClass
{
public function __construct($a , $b=6 , $c = "hh", $d, $e=76)
{

}
}

$class = new ReflectionClass("TestClass");
$method= $class-&gt;getMethod("__construct");
$parameter = $method-&gt;getParameters();

foreach ($parameter as $param)
{
if ($param-&gt;isDefaultValueAvailable())
{
if (is_null($param-&gt;getDefaultValue()))
echo $param-&gt;getName()." : null \n";
else
echo $param-&gt;getName()." : ".$param-&gt;getDefaultValue()."\n";
}
}
?>
[/sourcecode]

The above code returns only “e : 76” which is definitely not the expected value. And if you modify the TestClass like below

[sourcecode language=”php”]
class TestClass
{
public function __construct($a = "1", $b , $c = "string", $e=76)
{

}
}
[/sourcecode]

it will output
c : string
e : 76

Its a bug, right? I donno if already reported! And I didn’t test it in 5.2.2 but i guess it’s still there.