[PHP-BUG] Req #79369 [NEW]: Syntactic sugar for Closures ($object->method::function)
[email protected] ("txigreman at hotmail dot com") Wed, 11 Mar 2020 17:46:13 +0000
| Newsgroups | php.standards |
|---|---|
| Message-ID | <[email protected]> |
From: txigreman at hotmail dot com
Operating system:
PHP version: Irrelevant
Package: PHP Language Specification
Bug Type: Feature/Change Request
Bug description:Syntactic sugar for Closures ($object->method::function)
Description:
------------
Hi,
Actually, you can can create a Closure with any of this:
$closure = function() { return $this->method(); }
$closure = fn() => $this->method();
$closure = \Closure::fromCallable([$this, 'method']);
I think it would be greate to have a simpler way to create a Closure. I
suggest to add a simpler variant:
$closure = $this->method::function;
$closure = Class::staticMethod::function;
$closure = trim::function;
It mimics the functionality from MyClass:class and $object::class, so
the syntax is user-friendly.
Additionally, it does not uses a new keywork, so I think it has no
backwards compatibility breaks (or so I hope).
--
Edit bug report at https://bugs.php.net/bug.php?id=79369&edit=1
--
Fix committed: https://bugs.php.net/fix.php?id=79369&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=79369&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=79369&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=79369&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=79369&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=79369&r=support
Expected behavior: https://bugs.php.net/fix.php?id=79369&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=79369&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=79369&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=79369&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=79369&r=phptooold
Daylight Savings: https://bugs.php.net/fix.php?id=79369&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=79369&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=79369&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=79369&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=79369&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=79369&r=mysqlcfg