|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2019-02-03 17:46 UTC] sebastian@php.net
Description: ------------ It seems that there is a bug in PHP that when a PHAR is include()d or require()d and the PHAR's bootstrap script has a shebang such as "#!/usr/bin/env php" on its first line followed by "<?php declare(strict_types=1);" on its second line then PHP wrongly triggers a "strict_types declaration must be the very first statement in the script" compiler error. See https://github.com/sebastianbergmann/phpunit/issues/3509 for an issue that showcases this problem in the context of PHPUnit's phpunit.phar. I discussed this with Nikita who said "The strict_types error is correct, because the shebang line is interpreted as literal output (and will be printed to stdout unless you intercept that somehow). Shebangs are only stripped from the primary script if run via CLI. It would probably make sense to always strip them instead. This can probably only be fixed in 7.4 at the earliest, as it's a BC breaking change. Unless there is some phar-specific interaction here where it already strips the shebang but not for the purpose of strict_types handling)." PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 04:00:01 2025 UTC |
> the topic is about <?php declare(strict_types=1); and you come up with a simple missing the point? My point is that PHP sees the whole file as a single script, and that everything outside of <?php ?> is simply “rewritten” to be echoed. E.g. #!/usr/bin/env php <?php declare(strict_types=1); is compiled the same as <?php echo "#!/usr/bin/env php\n"; declare(strict_types=1); So, declare is *not* the “very first statement in the script”.