Re: [VOTE] Shorter Attribute Syntax Change
| From: | Andreas Leathley | Date: | Tue, 11 Aug 2020 16:26:02 +0000 |
| Subject: | Re: [VOTE] Shorter Attribute Syntax Change | ||
| References: | 1 2 3 4 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-111477@lists.php.net to get a copy of this message | ||
On 11.08.20 18:07, Sara Golemon wrote:
Writing this on PHP 7 (or any earlier version for that matter) would be valid syntax (ignored as a comment): #[SomeAttr(123)] function someFunc() {} That's what's meant by Forward Compatibility. Library/Framework authors could aggressively adopt attributes with the #[...] syntax, they can NOT do so with any other syntax.This would be a feature if libraries start parsing PHP token by token and start supporting the #[] syntax for the 7.x versions of PHP - then early adoption would be possible and it would be a real feature. But it seems unclear if that will happen, as it will probably have a heavy price on performance (and might have some complexity). And if some libraries implement it but others don't, then it might get confusing for users about why the new attribute syntax sometimes works and sometimes silently does nothing. It is also not perfect as multi-line attributes with #[ still break, or code with #[] followed by more code instead of a newline and then more code.