php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #71416 Reflection for ReflectionMethod::invoke considers second parameter as required
Submitted: 2016-01-19 20:36 UTC Modified: 2019-02-10 16:33 UTC
Votes:2
Avg. Score:4.5 ± 0.5
Reproduced:2 of 2 (100.0%)
Same Version:1 (50.0%)
Same OS:1 (50.0%)
From: ondrej at mirtes dot cz Assigned: carusogabriel (profile)
Status: Closed Package: Reflection related
PHP Version: Next major version OS: all
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: ondrej at mirtes dot cz
New email:
PHP Version: OS:

 

 [2016-01-19 20:36 UTC] ondrej at mirtes dot cz
Description:
------------
ReflectionMethod::invoke accepts one required parameter (the object) and then zero or more parameters that should be passed to the invoked method as stated in the documentation: https://secure.php.net/manual/en/reflectionmethod.invoke.php

But the reported parameters by reflection are not consistent with that. It does not consider the second parameter as variadic and it considers it as required.

I expect the second parameter to be reported as optional and as variadic.

Test script:
---------------
<?php

$ref = new ReflectionClass('ReflectionMethod');
foreach ($ref->getMethod('invoke')->getParameters() as $parameter) {
    var_dump($parameter->getName());
    var_dump($parameter->isOptional());
    var_dump($parameter->isVariadic());
    var_dump('---');
}

Expected result:
----------------
string(6) "object"
bool(false)
bool(false)
string(3) "---"
string(4) "args"
bool(true)
bool(true)
string(3) "---"

Actual result:
--------------
string(6) "object"
bool(false)
bool(false)
string(3) "---"
string(4) "args"
bool(false)
bool(false)
string(3) "---"

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-01-19 20:37 UTC] ondrej at mirtes dot cz
The test script has run here: https://3v4l.org/PXYvm
 [2016-02-02 11:57 UTC] krakjoe@php.net
-Status: Open +Status: Not a bug
 [2016-02-02 11:57 UTC] krakjoe@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

You appear to be looking at the HHVM output, the PHP output is consistent across all the versions we care about.
 [2016-02-02 12:06 UTC] ondrej at mirtes dot cz
I still think it's a bug, because the PHP reflection (in versions from 5.6.0 to 7.0.2) returns that the second parameter is not optional (so it's required) and that it's not variadic.

But according to the documentation of the method (https://secure.php.net/manual/en/reflectionmethod.invoke.php), it can be invoked with only just one parameter - the object.

As the method can be invoked with 1 to infinite number of parameters, I think the reflection of this method reports wrong information.

I already reported two inconsistencies in PHP reflection (https://bugs.php.net/bug.php?id=71077, https://bugs.php.net/bug.php?id=70960) which were acknowledged and fixed so I think this case is another of such inconsistencies.
 [2016-02-03 08:07 UTC] a at b dot c dot de
The HipHop Virtual Machine is a Facebook product, not something built by php.net. It's not the place of the official PHP manual to describe differences in third-party implementations/variants.
 [2016-02-03 08:15 UTC] ondrej at mirtes dot cz
I am not talking about HHVM at all. I am comparing PHP documentation and the current production behaviour to what PHP reflection reports. I haven't mentioned HHVM even once.
 [2016-12-22 17:46 UTC] rquadling@php.net
The reflection of the ReflectionMethod::invoke is certainly NOT in keeping with the documentation.

Running:

php --rc ReflectionMethod

and then looking at the invoke() method shows ...

    Method [ <internal:Reflection> public method invoke ] {

      - Parameters [2] {
        Parameter #0 [ <required> $object ]
        Parameter #1 [ <required> $args ]
      }
    }

Not HHVM. Not any PHP script. Just PHP.
 [2016-12-22 17:51 UTC] rquadling@php.net
-Status: Not a bug +Status: Open
 [2016-12-22 17:51 UTC] rquadling@php.net
Reopening.
 [2017-04-14 09:26 UTC] cmb@php.net
-Status: Open +Status: Analyzed
 [2017-04-14 09:26 UTC] cmb@php.net
The arginfo[1] is obviously wrong. We need
ZEND_BEGIN_ARG_INFO_EX() here.

[1] <https://github.com/php/php-src/blob/php-7.1.4/ext/reflection/php_reflection.c#L6421-L6424>
 [2018-09-21 05:39 UTC] carusogabriel@php.net
-PHP Version: Irrelevant +PHP Version: Next major version -Assigned To: +Assigned To: carusogabriel
 [2018-09-21 05:39 UTC] carusogabriel@php.net
This is only taking place in our next major version, as discussed in https://github.com/php/php-src/pull/3443
 [2018-09-21 05:40 UTC] carusogabriel@php.net
-Status: Analyzed +Status: Assigned
 [2019-02-10 16:33 UTC] carusogabriel@php.net
-Status: Assigned +Status: Closed
 [2019-02-10 16:33 UTC] carusogabriel@php.net
This was fixed and will be available at PHP 8.0

http://git.php.net/?p=php-src.git;a=commit;h=35db1ccdd
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 09:01:27 2024 UTC