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

From: Date: Sat, 22 Aug 2015 10:08:02 +0000
Subject: Req #70324 [Opn->Fbk]: Closure::call() equivalent for variadics
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-195423@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 Updated by: nikic@php.net Reported by: m dot chojnacki at muyo dot io Summary: Closure::call() equivalent for variadics -Status: Open +Status: Feedback Type: Feature/Change Request Package: Class/Object related PHP Version: 7.0.0RC1 Block user comment: N Private report: N New Comment: Are you looking for $closure->call($obj, ...$args)? Previous Comments: ------------------------------------------------------------------------ [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 (#195423) next »