Re: Could we kill call_user_func?
| From: | Johannes Schlüter | Date: | Tue, 19 Mar 2013 23:13:20 +0000 |
| Subject: | Re: Could we kill call_user_func? | ||
| References: | 1 2 3 4 5 6 7 8 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-66711@lists.php.net to get a copy of this message | ||
Julien Pauli <jpauli@php.net> wrote:
>On Tue, Mar 19, 2013 at 12:42 AM, Stas Malyshev
><smalyshev@sugarcrm.com>wrote:
>
>> Hi!
>>
>> > Also, AFAIR, call_user_func() doesn't work with functions using
>> references
>> > in args.
>>
>> Use call_user_func_array() for that, it supports refs.
>>
>
>Isn't it since 5.3 or so ?
Before 5.3 call_uer_func_array() could convert copied values in the array to references, something
like
<?php
$v = 42;
$a = array($v);
func f(&$param) { $param = 0; }
call_user_func_array('f', $a);
echo $v; // prints 0
?>
"worked", while obviously being wrong. This was fixed.
Anyways, both call_user_func() and call_user_func_array() have their place, one for doing dynamic
stuff, secondly for compatibility, no need to get rid of those. Adding syntactical sugar for calling
things is a different question, but a key element of the PHP language design is to have verbosity,
so that even people who don't know all constructs have a chance to search for it. We're
getting rid of this slowly (i.e. due to things like $a = [ ] ) but we houldn't loose this idea
completely.
johannes