Req #79369 [Com]: Syntactic sugar for Closures ($object->method::function)

From: Date: Thu, 12 Mar 2020 09:10:51 +0000
Subject: Req #79369 [Com]: Syntactic sugar for Closures ($object->method::function)
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-226046@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=79369&edit=1 ID: 79369 Comment by: txigreman at hotmail dot com Reported by: txigreman at hotmail dot com Summary: Syntactic sugar for Closures ($object->method::function) Status: Suspended Type: Feature/Change Request Package: *General Issues PHP Version: Irrelevant Block user comment: N Private report: N New Comment: 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? Previous Comments: ------------------------------------------------------------------------ [2020-03-11 22:06:26] rowan dot collins at gmail dot com Hi, This kind of broad feature request is generally best raised on the PHP Internals mailing list (https://www.php.net/mailing-lists.php) 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: https://externals.io/message/108459 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 [IMSoP] ------------------------------------------------------------------------ [2020-03-11 17:46:13] txigreman at hotmail dot com 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 this bug report at https://bugs.php.net/bug.php?id=79369&edit=1

« previous php.bugs (#226046) next »