Compatible Signature

By Christian Lück

../_images/compatible-signature.png

This piece of code shows a signature that changes with the version of PHP.

Indeed, in PHP 7.x, the comment starts with # and goes to the end of the line. This also covers the /* so the multiline comment doesn’t start, and the __invoke signature is the second one.

In PHP 8.0, the attributes #[PHP8] ends with its closing square bracket, and the signature of __invoke starts. By the end of the line, a multi-line comments starts, and covers the whole second line.

In the end, this code stays unchanged between PHP versions, although it toggles different signatures.

See Also

PHP Features