php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #41382 ReflectionParameter isDefaultValueAvailable() is not working as expected
Submitted: 2007-05-13 09:39 UTC Modified: 2007-05-13 10:30 UTC
From: hasin at pageflakes dot com Assigned:
Status: Not a bug Package: SPL related
PHP Version: 5.2.2 OS: Windows XP
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: hasin at pageflakes dot com
New email:
PHP Version: OS:

 

 [2007-05-13 09:39 UTC] hasin at pageflakes dot com
Description:
------------
The isDefaultValueAvailable() of ReflectionParameter object doesn't return true for any parameter if the next parameter in collection has no default value. To regenerate the bug, execute the following script



Reproduce code:
---------------
<?
class TestClass
{
	public function __construct($a , $b=6 , $c = "hh", $d, $e=76)
	{

	}
}

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

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




Expected result:
----------------
b : 6
c : hh
e : 76

Actual result:
--------------
e : 76

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-05-13 10:30 UTC] johannes@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

In your example $b and $c aren?t optional since an parameter without default value ($d) is present afterwards, too. We don?t store these values since the engine needs default values only for optional parameters.

See also example 17.9 http://de3.php.net/manual/en/functions.arguments.php
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 14:01:31 2024 UTC