Bug #74339 [Com]: BOGUS: Fatal error: strict_types declaration must be the very first statement

From: Date: Fri, 07 Apr 2017 12:18:51 +0000
Subject: Bug #74339 [Com]: BOGUS: Fatal error: strict_types declaration must be the very first statement
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-208382@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=74339&edit=1 ID: 74339 Comment by: narf at devilix dot net Reported by: spam2 at rhsoft dot net Summary: BOGUS: Fatal error: strict_types declaration must be the very first statement Status: Not a bug Type: Bug Package: Scripting Engine problem Operating System: Linux PHP Version: 7.1.3 Block user comment: N Private report: N New Comment: You shouldn't have CLI scripts within your webroot in the first place ... Previous Comments: ------------------------------------------------------------------------ [2017-04-02 11:15:16] spam2 at rhsoft dot net than at least ignore shebangs also with mod_php #!/usr/bin/php <?php declare(strict_types=1); if(PHP_SAPI != 'cli') { exit('CLI ONLY'); } ?> is also broken when called via browser which leads to fatal erros and so flood logs which is bad in case of emial reporting every 30 minutes when any of some hundret vhsost triggers any php-warning/error ------------------------------------------------------------------------ [2017-03-30 12:01:31] daverandom@php.net Shebangs are explicitly ignored. Everything else that appears outside PHP tags is considered to be script output. This is the way that PHP has always worked. To make your code work, do this: <?php declare(strict_types=1); ?> <html> <head><title>Test</title></head> <body> <?php // code here ?> </body> </html> ------------------------------------------------------------------------ [2017-03-30 11:57:17] peehaa@php.net This is defined behavior and is not a scripting engine problem ------------------------------------------------------------------------ [2017-03-30 11:47:56] spam2 at rhsoft dot net Description: ------------ for cli scripts it's no problem to start with a #!/usr/bin/php shebang followed by <?php declare(strict_types=1); as first line, in case of mod_php the sample below throws "PHP Fatal error: strict_types declaration must be the very first statement in the script" *it is* because PHP has no business to claim anything outside <?php ?> as part of "the script" Test script: --------------- <html> <head><title>Test</title></head> <body> <?php declare(strict_types=1); ?> </body> </html> ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=74339&edit=1

« previous php.bugs (#208382) next »