Re: [PHP-DEV] Could we kill call_user_func?

2013-03-21 Thread Steve Clay

On 3/21/13 7:37 AM, Derick Rethans wrote:

On Fri, 15 Mar 2013, Steve Clay wrote:


call_user_func() just seems so ugly now that we have nicer syntax in
so many other areas.


That doesn't mean we should just be ripping out functionality that works
perfectly fine.


I was not clear in my initial post. I don't want call_user_func removed, just made 
unnecessary. To reiterate why:


1. call_user_func fails reference args. (It's not a full substitute for a 
direct call)

2. Most callable values are already directly callable:
   ✓ func as string
   ✓ dynamic method as array
   ✓ static method as array
 static method as string
   ✓ Closure
   ✓ object with __invoke
 Closure in object property (I understand why this is off the table)
 expression containing Closure in object property

If always store the callable in a var, the situation is much better:

   ✓ func as string
   ✓ dynamic method as array
   ✓ static method as array
 static method as string
   ✓ Closure
   ✓ object with __invoke
   ✓ Closure in object property

How difficult would it be to support making this work?

$c = "Foo::bar";
$c();


Steve Clay
--
http://www.mrclay.org/

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] Could we kill call_user_func?

2013-03-21 Thread Derick Rethans
On Fri, 15 Mar 2013, Steve Clay wrote:

> call_user_func() just seems so ugly now that we have nicer syntax in 
> so many other areas.

That doesn't mean we should just be ripping out functionality that works 
perfectly fine.

cheers,
Derick

-- 
http://derickrethans.nl | http://xdebug.org
Like Xdebug? Consider a donation: http://xdebug.org/donate.php
twitter: @derickr and @xdebug
Posted with an email client that doesn't mangle email: alpine

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] Could we kill call_user_func?

2013-03-20 Thread Bob Weinand
Am 15.3.2013 um 18:57 schrieb Stas Malyshev :

> Hi!
> 
>> why not enable then this "getCallback()();"?
> 
> There's an RFC for that: https://wiki.php.net/rfc/fcallfcall
> but it has some edge cases which I didn't have time to figure out yet.

Is it possible to add this alternative rule for function_call in 
zend_language_parser.y:
parenthesis_expr { zend_do_begin_dynamic_function_call(&$1, 0 TSRMLS_CC); }
function_call_parameter_list { zend_do_end_function_call(&$1, &$$, &$3, 0, 
$2.u.op.opline_num TSRMLS_CC); zend_do_extended_fcall_end(TSRMLS_C); }

So that you can write ($this->closure)(); (for invoking Closures instead of 
first assigning it, then calling the Closure or writing 
$this->closure->invoke())

Or write (getCallback())(). There should be then no edge cases as it is 
properly delimited by the parenthesis.

I've shortly tested this with no new bugs.

Short example:
function a () { return "b"; }
function b () { return "c"; }
print (a())()."\n"; // prints c

function a () { return function () { print "a\n"; }; }
(a())(); // prints a

I also think this with parenthesis around it it is clearer what's being done: 
the first part evaluated and then the second executed. (If I would have to 
choose I would prefer the parenthesis...)


Bob Weinand

p.s.: I'm wondering why, with this little patch, (function () { print "a"; 
})(); is throwing a fatal error telling me a function name must be a string 
while ($temp = function () { print "a"; })(); is working perfectly?! (I think 
this is the condition which fails: 
http://lxr.php.net/xref/PHP_TRUNK/Zend/zend_vm_def.h#2676, but I'm not 100% 
sure and now I'm too tired to investigate further into it...)
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] Could we kill call_user_func?

2013-03-19 Thread Johannes Schlüter


Julien Pauli  wrote:

>On Tue, Mar 19, 2013 at 12:42 AM, Stas Malyshev
>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



"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

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] Could we kill call_user_func?

2013-03-19 Thread Stas Malyshev
Hi!

> Use call_user_func_array() for that, it supports refs.
> 
> 
> Isn't it since 5.3 or so ?

I think it always has been this way. See: http://3v4l.org/CGCLS

-- 
Stanislav Malyshev, Software Architect
SugarCRM: http://www.sugarcrm.com/
(408)454-6900 ext. 227

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] Could we kill call_user_func?

2013-03-19 Thread Julien Pauli
On Tue, Mar 19, 2013 at 12:42 AM, Stas Malyshev 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 ?


Julien.Pauli


Re: [PHP-DEV] Could we kill call_user_func?

2013-03-18 Thread Stas Malyshev
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.


-- 
Stanislav Malyshev, Software Architect
SugarCRM: http://www.sugarcrm.com/
(408)454-6900 ext. 227

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] Could we kill call_user_func?

2013-03-18 Thread Nikita Nefedov

On Mon, 18 Mar 2013 19:03:41 +0400, Julien Pauli  wrote:

On Mon, Mar 18, 2013 at 3:33 PM, Anthony Ferrara  
wrote:



Angel,

On 18/03/13 14:04, Julien Pauli wrote:

> Also, AFAIR, call_user_func() doesn't work with functions using
> references in args. Julien.Pauli
AFAIK it does.
Do you have an example where it doesn't?



It definitely does not:

http://3v4l.org/C8Kme

And if you try call-time-pass-by-reference, it gets worse:

http://3v4l.org/pI89l


Yeah, that's what I remembered. call_user_func() is not exactly the same  
as

calling the function, when references come to scene, it just wont work.

Same with _array() implementation.

Julien.Pauli


call_user_func_array will work ok. This is the only call_user_func problem.

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] Could we kill call_user_func?

2013-03-18 Thread Julien Pauli
On Mon, Mar 18, 2013 at 3:33 PM, Anthony Ferrara wrote:

> Angel,
>
> On 18/03/13 14:04, Julien Pauli wrote:
>> > Also, AFAIR, call_user_func() doesn't work with functions using
>> > references in args. Julien.Pauli
>> AFAIK it does.
>> Do you have an example where it doesn't?
>>
>
> It definitely does not:
>
> http://3v4l.org/C8Kme
>
> And if you try call-time-pass-by-reference, it gets worse:
>
> http://3v4l.org/pI89l
>
>
Yeah, that's what I remembered. call_user_func() is not exactly the same as
calling the function, when references come to scene, it just wont work.

Same with _array() implementation.

Julien.Pauli


RE: [PHP-DEV] Could we kill call_user_func?

2013-03-18 Thread nathan
> Angel,
> 
> On 18/03/13 14:04, Julien Pauli wrote:
> > > Also, AFAIR, call_user_func() doesn't work with functions using 
> > > references in args. Julien.Pauli
> > AFAIK it does.
> > Do you have an example where it doesn't?
> >
> 
> It definitely does not:
> 
> http://3v4l.org/C8Kme
> 
> And if you try call-time-pass-by-reference, it gets worse:
> 
> http://3v4l.org/pI89l
> 
> Anthony
Although it does not work with call_user_func() it does work with
call_user_func_array() see:
http://3v4l.org/GdUmM


-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] Could we kill call_user_func?

2013-03-18 Thread Anthony Ferrara
Angel,

On 18/03/13 14:04, Julien Pauli wrote:
> > Also, AFAIR, call_user_func() doesn't work with functions using
> > references in args. Julien.Pauli
> AFAIK it does.
> Do you have an example where it doesn't?
>

It definitely does not:

http://3v4l.org/C8Kme

And if you try call-time-pass-by-reference, it gets worse:

http://3v4l.org/pI89l

Anthony


Re: [PHP-DEV] Could we kill call_user_func?

2013-03-18 Thread Ángel González
On 18/03/13 14:04, Julien Pauli wrote:
> Also, AFAIR, call_user_func() doesn't work with functions using
> references in args. Julien.Pauli 
AFAIK it does.
Do you have an example where it doesn't?


-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] Could we kill call_user_func?

2013-03-18 Thread Julien Pauli
On Sat, Mar 16, 2013 at 7:51 AM, Sara Golemon  wrote:

> > ${'_'.!$_=getCallback()}();
> >
> Well now, that's an... interesting abuse of resolution order and type
> juggling.
>
>
Really crazy, yeah

Also, AFAIR, call_user_func() doesn't work with functions using references
in args.

Julien.Pauli


Re: [PHP-DEV] Could we kill call_user_func?

2013-03-15 Thread Sara Golemon
> ${'_'.!$_=getCallback()}();
>
Well now, that's an... interesting abuse of resolution order and type juggling.

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] Could we kill call_user_func?

2013-03-15 Thread Sebastian Krebs
2013/3/15 Stas Malyshev 

> Hi!
>
> > why not enable then this "getCallback()();"?
>
> There's an RFC for that: https://wiki.php.net/rfc/fcallfcall
> but it has some edge cases which I didn't have time to figure out yet.
>

In the long run I think it would be great :) Earlier I also realized, that

[MyClass::class, 'methodName']();

doesn't work either.

Regards,
Sebastian


>
>
> --
> Stanislav Malyshev, Software Architect
> SugarCRM: http://www.sugarcrm.com/
> (408)454-6900 ext. 227
>
> --
> PHP Internals - PHP Runtime Development Mailing List
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


-- 
github.com/KingCrunch


Re: [PHP-DEV] Could we kill call_user_func?

2013-03-15 Thread Stas Malyshev
Hi!

> why not enable then this "getCallback()();"?

There's an RFC for that: https://wiki.php.net/rfc/fcallfcall
but it has some edge cases which I didn't have time to figure out yet.


-- 
Stanislav Malyshev, Software Architect
SugarCRM: http://www.sugarcrm.com/
(408)454-6900 ext. 227

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] Could we kill call_user_func?

2013-03-15 Thread Bob Weinand
Am 15.3.2013 um 16:59 schrieb Anthony Ferrara :

> Bob,
> 
> call_user_func is not call_user_func_array
> 
> call_user_func($func) is the same as $func(). In any way.
> 
> Not in any way. call_user_func accepts any expression for the function to 
> call. `$func()` only accepts callables.
> 
> Example:
> 
> call_user_func(getCallback()); 
> getCallback()(); // <-- syntax error.
> 
> You *could* solve it with variable foo:
> 
> ${'_'.!$_=getCallback()}();
> 
> But I'd stick to call_user_func()...

Hey,

why not enable then this "getCallback()();"?

but yes, call_user_func should remain there alone in the combination with 
call_user_func_array.


Bob Weinand

Re: [PHP-DEV] Could we kill call_user_func?

2013-03-15 Thread Anthony Ferrara
Bob,

call_user_func is not call_user_func_array
>
> call_user_func($func) is the same as $func(). In any way.
>

Not in any way. call_user_func accepts any expression for the function to
call. `$func()` only accepts callables.

Example:

call_user_func(getCallback());
getCallback()(); // <-- syntax error.

You *could* solve it with variable foo:

${'_'.!$_=getCallback()}();

But I'd stick to call_user_func()...


Re: [PHP-DEV] Could we kill call_user_func?

2013-03-15 Thread Bob Weinand
Am 15.3.2013 um 15:50 schrieb Ángel González :

> On 15/03/13 15:19, Steve Clay wrote:
>> I'm sure this question has been discussed before, so if anyone can
>> point to me to links or briefly recap I'd appreciate it.
>> 
>> Why can't we make $someCallable() always work? E.g. http://3v4l.org/FLpAq
>> 
>> I understand the problem of $obj->foo() where ->foo is a callable
>> property. The workaround could be:
>> 
>> ($obj->foo)();
>> 
>> call_user_func() just seems so ugly now that we have nicer syntax in
>> so many other areas.
>> 
>> Steve Clay
> No.
> 
> What if I want to call functions with a variable number of arguments?
> 
> For instance, the common piece of a hook system implementation, where
> the arguments of the functions called vary depending on the hook.



call_user_func is not call_user_func_array

call_user_func($func) is the same as $func(). In any way.

Bob Weinand
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] Could we kill call_user_func?

2013-03-15 Thread Ángel González
On 15/03/13 15:19, Steve Clay wrote:
> I'm sure this question has been discussed before, so if anyone can
> point to me to links or briefly recap I'd appreciate it.
>
> Why can't we make $someCallable() always work? E.g. http://3v4l.org/FLpAq
>
> I understand the problem of $obj->foo() where ->foo is a callable
> property. The workaround could be:
>
> ($obj->foo)();
>
> call_user_func() just seems so ugly now that we have nicer syntax in
> so many other areas.
>
> Steve Clay
No.

What if I want to call functions with a variable number of arguments?

For instance, the common piece of a hook system implementation, where
the arguments of the functions called vary depending on the hook.


-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] Could we kill call_user_func?

2013-03-15 Thread Sebastian Krebs
2013/3/15 Steve Clay 

> I'm sure this question has been discussed before, so if anyone can point
> to me to links or briefly recap I'd appreciate it.
>
> Why can't we make $someCallable() always work? E.g. http://3v4l.org/FLpAq
>
> I understand the problem of $obj->foo() where ->foo is a callable
> property. The workaround could be:
>
> ($obj->foo)();
>
> call_user_func() just seems so ugly now that we have nicer syntax in so
> many other areas.
>

You don't need to use it, if you don't like it.


>
>
> Steve Clay
> --
> http://www.mrclay.org/
>
> --
> PHP Internals - PHP Runtime Development Mailing List
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


-- 
github.com/KingCrunch