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

From: Date: Thu, 30 Mar 2017 12:01:37 +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-208180@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: daverandom@php.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: 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> Previous Comments: ------------------------------------------------------------------------ [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 (#208180) next »