php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #62988 ReflectionParameter::getDefaultValue throws when it shouldn't
Submitted: 2012-09-01 08:44 UTC Modified: 2012-09-01 11:31 UTC
From: juzna dot cz at gmail dot com Assigned: laruence (profile)
Status: Closed Package: Reflection related
PHP Version: 5.3.16 OS: Ubuntu
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: juzna dot cz at gmail dot com
New email:
PHP Version: OS:

 

 [2012-09-01 08:44 UTC] 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)


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-09-01 10:41 UTC] 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-09-01 10:41 UTC] laruence@php.net
-Status: Open +Status: Feedback
 [2012-09-01 11:04 UTC] juzna dot cz at gmail dot com
Thanks, works as expected.
 [2012-09-01 11:31 UTC] laruence@php.net
the fix of #62715  has not been merged(actually only merged one of the two) into 
release.
 [2012-09-01 11:31 UTC] laruence@php.net
-Status: Feedback +Status: Closed -Assigned To: +Assigned To: laruence
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 18 14:01:31 2024 UTC