php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #70324 Closure::call() equivalent for variadics
Submitted: 2015-08-22 02:45 UTC Modified: 2015-08-22 12:06 UTC
From: m dot chojnacki at muyo dot io Assigned:
Status: Closed Package: Class/Object related
PHP Version: 7.0.0RC1 OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: m dot chojnacki at muyo dot io
New email:
PHP Version: OS:

 

 [2015-08-22 02:45 UTC] 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.


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-08-22 10:08 UTC] nikic@php.net
-Status: Open +Status: Feedback
 [2015-08-22 10:08 UTC] nikic@php.net
Are you looking for $closure->call($obj, ...$args)?
 [2015-08-22 12:06 UTC] m dot chojnacki at muyo dot io
-Status: Feedback +Status: Closed
 [2015-08-22 12:06 UTC] m dot chojnacki at muyo dot io
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 :)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 19:01:28 2024 UTC