|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #79369 Syntactic sugar for Closures ($object->method::function)
Submitted: 2020-03-11 17:46 UTC Modified: 2020-03-11 23:12 UTC
From: txigreman at hotmail dot com Assigned:
Status: Suspended Package: *General Issues
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: txigreman at hotmail dot com
New email:
PHP Version: OS:


 [2020-03-11 17:46 UTC] txigreman at hotmail dot com

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).


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2020-03-11 17:52 UTC]
-Package: PHP Language Specification +Package: *General Issues
 [2020-03-11 22:06 UTC] rowan dot collins at gmail dot com

This kind of broad feature request is generally best raised on the PHP Internals mailing list ( which gets a lot more attention than this bug tracker.

As it happens, there was a discussion on precisely this feature last month! You can see an archive here:

The main points of discussion were:

* Should it return a string (like ::class does) or a closure?
* Function names are resolved at run-time, so it couldn't be processed at compile-time like ::class (mostly) is (this also means we can't have a single ::nameof syntax)
* A few alternative syntaxes were suggested, particularly to better handle instance and static methods.

Thanks for getting involved. :)
Rowan Tommins
 [2020-03-11 23:12 UTC]
-Status: Open +Status: Suspended
 [2020-03-12 09:10 UTC] txigreman at hotmail dot com
Hi Rowan,

Thanks for your reply.

I've readed the externals link, and subscribed to the internals mailing list. Really hoping to colaborate.
How can I write to the chain? Do I Have to wait to get an email and then reply to it?
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Sat Sep 25 17:03:36 2021 UTC