|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2006-09-29 13:15 UTC] matthew at zend dot com
Description:
------------
ReflectionMethod::invoke() and ReflectionMethod::invokeArgs() implementations currently do not support the same functionality.
Currently, ReflectionMethod::invoke() can be called using a string class name as the first argument *if* the method is declared static. However, ReflectionMethod::invokeArgs(), called the same way, raises a warning and does not invoke the method:
Warning: ReflectionMethod::invokeArgs() expects parameter 1 to be object, string given
Calling with a string class name is undocumented currently, but a useful feature to have. I'd request that invokeArgs() be made to match the current invoke() functionality, and the documentation updated to indicate this usage.
Reproduce code:
---------------
<?php
class MyClass
{
public static function doSomething()
{
echo "Did it!\n";
}
}
$r = new ReflectionMethod('MyClass', 'doSomething');
$args = array();
$r->invoke('MyClass', array());
$r->invokeArgs('MyClass', $args);
Expected result:
----------------
Did it!
Did it!
Actual result:
--------------
Did it!
Warning: ReflectionMethod::invokeArgs() expects parameter 1 to be object, string given in ... line 13
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Oct 30 22:00:01 2025 UTC |
If anybody needs invokeArgs functionality though the following code works fine: <? class A { public static function run() { $class = new ReflectionClass('B'); $method = $class->getMethod('foo'); call_user_func_array(array($method, 'invoke'), array('B', 1, 2)); } } class B extends A { public static function foo($v1, $v2) { echo $v1." / ".$v2; } } B::run(); Expected result: ---------------- 1 / 2 Actual result: -------------- 1 / 2