3 ms·
They are not comments they are php8 attributes
by Arkounay 3y ago
They are not comments they are php8 attributes
- jusssi 3y agoPHP8 attributes are comments with a special format.
- hazn 3y agoThey are not. Attributes are metadata that can reflected/accessed at runtime: https://php.watch/versions/8.0/attributes https://php.watch/versions/8.0/attributes
- zeroimpl 3y agoComments can also be accessed at runtime :)
- psychoslave 3y agoAnd a program can generally read its source code and make fancy adhoc interpretation, sure. That’s nowhere close to specified facilities that you are guarantied to be able to use with a fair amount of trust in the resulting outcome with the regular toolbox.
- Nullabillity 3y ago# is a PHP comment syntax. #[foo] is as much of a comment as #foo is.
- pfsalter 3y agoNot 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.php https://www.php.net/manual/en/language.attributes.overview.p...
- Nullabillity 3y agoIt'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.
- tored 3y agoThis 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.
- Nullabillity 3y agoIt 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).
- tored 3y agoOkay, 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.