|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2012-04-18 15:19 UTC] admin dot windows at gmail dot com
Description:
------------
I have discovered weird behaviour of call_user_func that breaks class autoloader by providing scrambled class name for example instead of "myObject" it provides "zw87zl18".
This event only occurs if you are using custom class autoloader and requesting static method that is not declared as static.
Test script:
---------------
//FILE: myObject.php
class myObject {
public static function method1(){var_dump(__METHOD__);}
public function method2(){var_dump(__METHOD__);}
}
//FILE: index.php
ini_set('display_errors', TRUE);
function __autoload($className) {
include sprintf('%s/%s.php', getcwd(), $className);
}
call_user_func(array('myObject', 'method1'));//works fine
call_user_func(array('myObject', 'method2'));//produce an error
Expected result:
----------------
string(17) "myObject::method1"
string(17) "myObject::method2"
Actual result:
--------------
string(17) "myObject::method1"
Warning: include(/www/zw87zl18.php) [function.include]: failed to open stream: No such file or directory in /www/index.php on line 9
Warning: include() [function.include]: Failed opening '/www/zw87zl18.php' for inclusion (include_path='.:/usr/share/pear:/usr/share/php') in /www/index.php on line 9
Warning: include(/www/zw87zl18.php) [function.include]: failed to open stream: No such file or directory in /www/index.php on line 9
Warning: include() [function.include]: Failed opening '/www/zw87zl18.php' for inclusion (include_path='.:/usr/share/pear:/usr/share/php') in /www/index.php on line 9
string(17) "myObject::method2"
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Dec 01 07:00:01 2025 UTC |
I am encountering a very similar problem. I use call_user_func_array to execute a static class method and I get a corrupted call. Unlike the original report, it's not the class name that's corrupted, but rather the method name in my case. Here's the code: return array_keys(call_user_func_array(array(get_called_class(), 'fielddefs'), func_get_args())); By the time the method is called, the method name is completely corrupted to become this method name: &j-2!?{7k Here's a string-ified backtrace: exception 'ErrorException' with message 'WARNING: Attempt to call e_member->&j- 2!?{7k failed because "" is not callable (iaw:element:member.&j-2!?{7k).' in /home7/inneract/sites/iawtest/lib/capcelinstance.php:650 Stack trace: #0 [internal function]: CapcelInstance->__call('&j-2!?{7k', Array) #1 [internal function]: e_member->&j-2!?{7k(Object(CapcelPortal), 10, NULL, Array) #2 /home7/inneract/sites/iawtest/lib/capcelinstance.php(282): call_user_func_array(Array, Array) #3 [internal function]: CapcelInstance->field_list(Object(CapcelPortal), 10, NULL, Array) #4 /home7/inneract/sites/iawtest/lib/capcelinstance.php(324): call_user_func_array(Array, Array) #5 /home7/inneract/sites/iawtest/app/iaw/a_establishmember.php(115): CapcelInstance->render_fields(Object(CapcelPortal), 10, NULL, Array) #6 /home7/inneract/sites/iawtest/app/web/scheduler.php(31): a_EstablishMember- >render(Object(CapcelPortal), Array) #7 {main} Frame 0 and the exception itself are only symptoms. The problem is first visible in frame 1 and there is no trace of a problem when call_user_func_array() is called in line 282 of the code as shown in frame 2. I have examined a full backtrace in detail and confirmed that there is no corruption of any kind visible going into the call to call_user_func_array(). The method "fielddefs" does exist in the class CapcelInstance, of which e_member is a subclass. I strongly believe there's a real bug in call_user_func_array... some kind of data corruption occurs as it executes and before it calls the target callable.