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
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: jrs2k5 at gmail dot com
New email:
PHP Version: OS:

 

 [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

Pull Requests

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-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 12:01:31 2024 UTC