Hacker News new | ask | show | jobs
by pfsalter 1130 days ago
Not since PHP8 it's not [0], it's a real part of the language that you can read and view using reflection

[0] https://www.php.net/manual/en/language.attributes.overview.p...

1 comments

It's still using a subset of the comment syntax, and will still be ignored as comments rather than hard-fail in earlier versions.

Unknown attributes are also ignored silently, which isn't really a good sign.

This is one of the reasons I like PHP, in newer PHP versions it is an attribute but in older versions it is just a comment. Clever and backwards compatible.
It isn't backwards compatible (`#[foo` used to be legal PHP 7, but is illegal in PHP 8).

It may technically be forwards compatible syntactically (`#[foo]` will, as you say, just be ignored by PHP 7), but that's an anti-feature (assuming that the attribute isn't a no-op, it'll presumably break something else).

Okay, forward compatible. It makes it easier for framework and library maintainers to support multiple versions of PHP, which is nice.

> `#[foo` used to be legal PHP 7, but is illegal in PHP 8).

So it is not a comment in PHP8 then.