php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #50049 ReflectionMethod::invokeArgs() alters arguments passed to reflected method
Submitted: 2009-11-01 14:27 UTC Modified: 2009-11-01 15:22 UTC
From: jrs2k5 at gmail dot com Assigned:
Status: Not a bug Package: Reflection related
PHP Version: 5.3.0 OS: Windows XP
Private report: No CVE-ID: None
 [2009-11-01 14:27 UTC] jrs2k5 at gmail dot com
Description:
------------
The definition for ReflectionMethod::invokeArgs() indicates that it takes an array as its 2nd argument.  I assume this array is then passed to the method being reflected, however it is not.
--
Additionally, if I use type hinting in the reflected method, (e.g. public function callMe(array $args)) the script terminates with a fatal error.



Reproduce code:
---------------
<?php

class MyClass {

    public static function test() {
        $obj = new MyClass();
        $ro = new ReflectionObject($obj);
        $rm = $ro->getMethod("callMe");
        $args = array("key1" => "value1", "key2" => "value2", "key3" => "value3");
        print_r($args);
        $rm->invokeArgs($obj, $args);
    }

    public function callMe($args) {
        print_r($args);
    }
}

MyClass::test();

?>

Expected result:
----------------
Array
(
    [key1] => value1
    [key2] => value2
    [key3] => value3
)
Array
(
    [key1] => value1
    [key2] => value2
    [key3] => value3
)


Actual result:
--------------
Array
(
    [key1] => value1
    [key2] => value2
    [key3] => value3
)
value1

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-11-01 15:22 UTC] felipe@php.net
You must to use: $rm->invokeArgs($obj, array($args));
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Mon Apr 22 20:01:25 2019 UTC