Bug #71416 [Com]: Reflection for ReflectionMethod::invoke considers second parameter as required

From: Date: Wed, 03 Feb 2016 08:07:08 +0000
Subject: Bug #71416 [Com]: Reflection for ReflectionMethod::invoke considers second parameter as required
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-199013@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=71416&edit=1

 ID:                 71416
 Comment by:         a at b dot c dot de
 Reported by:        ondrej at mirtes dot cz
 Summary:            Reflection for ReflectionMethod::invoke considers
                     second parameter as required
 Status:             Not a bug
 Type:               Bug
 Package:            Reflection related
 Operating System:   all
 PHP Version:        Irrelevant
 Block user comment: N
 Private report:     N

 New Comment:

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.


Previous Comments:
------------------------------------------------------------------------
[2016-02-02 12:06:21] 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-02 11:57:22] 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-01-19 20:37:41] ondrej at mirtes dot cz

The test script has run here: https://3v4l.org/PXYvm

------------------------------------------------------------------------
[2016-01-19 20:36:57] 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) "---"


------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=71416&edit=1


Thread (10 messages)

« previous php.bugs (#199013) next »