php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #29523 ReflectionParameter::isOptional() is incorrect
Submitted: 2004-08-04 14:02 UTC Modified: 2004-08-05 00:49 UTC
From: Jared dot Williams1 at ntlworld dot com Assigned: helly (profile)
Status: Closed Package: Class/Object related
PHP Version: 5.1.0-dev OS: *
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: Jared dot Williams1 at ntlworld dot com
New email:
PHP Version: OS:

 

 [2004-08-04 14:02 UTC] Jared dot Williams1 at ntlworld dot com
Description:
------------
ReflectionParameter::isOptional() does not return the correct optional status of some parameters.

ReflectionFunction::getNumberOfRequiredParameters() returns the current number of required parameters, but when iterator through the ReflectionFunction::getParamaters() counting parameters that are not marked as optional, the value calculated is incorrect.


Reproduce code:
---------------
class TestClass
{
}
function optionalTest(TestClass $a, TestClass $b, $c = 3)
{
}

$function = new ReflectionFunction('optionalTest'); 
$numberOfNotOptionalParameters = 0;
$numberOfOptionalParameters = 0;
foreach($function->getParameters() as $parameter)
	if ($parameter->isOptional())
		++$numberOfOptionalParameters;
	else
		++$numberOfNotOptionalParameters;
var_dump($function->getNumberOfRequiredParameters());
var_dump($numberOfNotOptionalParameters);

Expected result:
----------------
int(2) int(2) 

Actual result:
--------------
int(2) int(0) 

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-08-05 00:48 UTC] helly@php.net
Thank you for your bug report. This issue has already been fixed
in the latest released version of PHP, which you can download at 
http://www.php.net/downloads.php
 [2004-08-05 00:49 UTC] helly@php.net
Sorry will be fixed for 5.1.0
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue May 14 19:01:35 2024 UTC