Req #76904 [Opn->Fbk]: New Closure class method suggestion

From: Date: Thu, 20 Sep 2018 12:52:34 +0000
Subject: Req #76904 [Opn->Fbk]: New Closure class method suggestion
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-217156@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=76904&edit=1 ID: 76904 Updated by: cmb@php.net Reported by: hello at rayfung dot hk Summary: New Closure class method suggestion -Status: Open +Status: Feedback Type: Feature/Change Request Package: *General Issues PHP Version: 7.2.10 -Assigned To: +Assigned To: cmb Block user comment: N Private report: N New Comment: Indeed, what's wrong with ::call() and using argument unpacking (aka. spread operator)? Previous Comments: ------------------------------------------------------------------------ [2018-09-19 17:22:13] Wes dot example at example dot org so, for instance $closure->call($three, ...['Peter', 30]); ------------------------------------------------------------------------ [2018-09-19 17:20:54] Wes dot example at example dot org already exists. $closure->call($newThis, ...$arguments); ------------------------------------------------------------------------ [2018-09-19 17:16:45] hello at rayfung dot hk Description: ------------ Closure::apply — Binds and calls the closure with an array of parameters #Description ``` public mixed Closure::apply ( object $newthis [, array $param_arr ] ) ``` Temporarily binds the closure to newthis, and calls it with any given array of parameters. #Parameters newthis The object to bind the closure to for the duration of the call. param_arr The parameters to be passed to the callback, as an indexed array. #Return Values Returns the return value of the closure. Test script: --------------- $closure = function($name, $age) { return $name . ' is ' . $age . ' years old'; } $closure->apply($three, ['Peter', 30]); Expected result: ---------------- Peter is 30 years old ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=76904&edit=1

« previous php.bugs (#217156) next »