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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
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

Pull Requests

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-2025 The PHP Group
All rights reserved.
Last updated: Wed Jan 15 10:01:29 2025 UTC