Bug #52937 [Com]: call_user_func warning is inappropriate

From: Date: Sun, 22 Mar 2015 22:30:30 +0000
Subject: Bug #52937 [Com]: call_user_func warning is inappropriate
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-191532@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=52937&edit=1 ID: 52937 Comment by: cmbecker69 at gmx dot de Reported by: mryaggi at hotmail dot com Summary: call_user_func warning is inappropriate Status: Wont fix Type: Bug Package: Scripting Engine problem Operating System: Seven PHP Version: 5.3.3 Block user comment: N Private report: N New Comment: > $func() isn't always an option as it is not usable with method > calls, etc. To my knowledge, variable functions work for all callables (i.e. is_callable($func) !== true) since PHP 5.4. Older versions have already reached their EOL. Previous Comments: ------------------------------------------------------------------------ [2015-03-22 17:15:24] georgir at gmail dot com wow, that wontfix... as said above, call_user_func_array is affected by the same bug. and even for call_user_func, $func() isn't always an option as it is not usable with method calls, etc. ------------------------------------------------------------------------ [2015-03-21 20:23:02] nikic@php.net Closing as Won't Fix, because a) since PHP 5.4 you can just use $callback($arg1, $arg2, ...) instead (which supports references) b) you can use call_user_func_array() if you really want to stick with it. ------------------------------------------------------------------------ [2012-03-20 08:21:03] georgir at gmail dot com The "workaround" from the last comment is not a good idea, because it can not be applied generally. If you use call_user_func_array('foo', array(&$b)) when the function foo takes an argument by copy instead of by reference and modifies it thinking it doesn't matter, $b will still be modified, which is most certainly undesired. Also, the issue is more serious than described in the original post. It affects call_user_func_array as well as call_user_func, and it is not just a warning that is given, but the whole function does not get executed. This is actually a big deal, it can break a lot of programs. A setting to allow execution of the function in this case would be welcome. ------------------------------------------------------------------------ [2011-08-04 02:11:00] lucas at threeamdesign dot com to work around this problem put the reference in the argument array. e.g.: function foo(&$bar) { $bar = 5; } $a = 1; $b = 2; call_user_func('foo', $a); call_user_func_array('foo', array(&$b)); var_dump($a, $b); gives int(1) int(5) ------------------------------------------------------------------------ [2010-10-11 11:00:54] mryaggi at hotmail dot com Ok, I'm going to keep it simple. You say "[I] have to use call_user_func_array instead". Please show me how. Note : I'm just trying to avoid the warning properly. This would be quite a solution : call_user_func('ExprectRef', & $p); call_user_func_array('ExprectRef',array( & $p)); But it's a pity you have to write & TWICE. One in the signature, one in the call_user_func call. ...it looks so much like the depreciated call-time pass-by-reference. Don't you think? ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at https://bugs.php.net/bug.php?id=52937 -- Edit this bug report at https://bugs.php.net/bug.php?id=52937&edit=1

« previous php.bugs (#191532) next »