Req #70324 [Fbk->Csd]: Closure::call() equivalent for variadics

From: Date: Sat, 22 Aug 2015 12:06:24 +0000
Subject: Req #70324 [Fbk->Csd]: Closure::call() equivalent for variadics
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-195425@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=70324&edit=1 ID: 70324 User updated by: m dot chojnacki at muyo dot io Reported by: m dot chojnacki at muyo dot io Summary: Closure::call() equivalent for variadics -Status: Feedback +Status: Closed Type: Feature/Change Request Package: Class/Object related PHP Version: 7.0.0RC1 Block user comment: N Private report: N New Comment: Yes. Pardon my being stupid. I must've missed the memo about argument unpacking in 5.6 and only got the one about variadic signatures :) Previous Comments: ------------------------------------------------------------------------ [2015-08-22 10:08:01] nikic@php.net Are you looking for $closure->call($obj, ...$args)? ------------------------------------------------------------------------ [2015-08-22 02:45:19] m dot chojnacki at muyo dot io Description: ------------ As of PHP7, Closure::call() allows us to skip the intermediary step of binding to a different object before invoking the closure. However, it assumes the list of arguments is known beforehand, just like call_user_func() does. For variadics that list is generally unknown. Having to rely on call_user_func_array() in this case means we're still forced to first manually bind the Closure before invoking it. Sure, it works, but from my perspective this feels like a missing part of a nice addition to PHP and is somewhat unintuitive that you can do one, but can't do the other. In JavaScript, for example, this use case is served by separate call() and apply() function prototype methods, where apply() accepts a scope and an array of arguments while call() works like the equivalent Closure:call() in PHP7. I would very much love to see a similar implementation in PHP and find it is a suitable, complementary addition. ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=70324&edit=1

« previous php.bugs (#195425) next »