Bug #66566 [Com]: Parse error when files contain shebang and NS declaration

From: Date: Tue, 29 Nov 2016 19:10:00 +0000
Subject: Bug #66566 [Com]: Parse error when files contain shebang and NS declaration
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-205683@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=66566&edit=1 ID: 66566 Comment by: miken32 at gmail dot com Reported by: eric at wepay dot com Summary: Parse error when files contain shebang and NS declaration Status: Assigned Type: Bug Package: Scripting Engine problem Operating System: OS X, CentOS PHP Version: 5.3 Assigned To: willfitch Block user comment: N Private report: N New Comment: No, this remains an issue in version 7.0.13. Previous Comments: ------------------------------------------------------------------------ [2016-06-28 11:07:03] yunosh@php.net Fixed in PHP 7 ------------------------------------------------------------------------ [2014-01-24 03:54:34] willfitch@php.net Verified from PHP 5.3+ ------------------------------------------------------------------------ [2014-01-24 02:23:52] eric at wepay dot com Description: ------------ If a PHP CLI scripts starts with a shebang and contains a namespace declaration, executing it via stdin incorrectly raises a fatal error stating the NS declaration must be the first thing in the file. This is a relatively common thing to do when, for example, trying to lint a file in a commit hook (git show ... | php -l) Test script: --------------- eric@Eric-MBP ~: cat testcase.php #!/usr/bin/env php <?php namespace Boris; eric@Eric-MBP ~: php -l testcase.php No syntax errors detected in testcase.php eric@Eric-MBP ~: cat testcase.php | php -l Fatal error: Namespace declaration statement has to be the very first statement in the script in - on line 4 Errors parsing - Expected result: ---------------- No error, return code 0. This is what happens if the file does not contain the leading shebang. Actual result: -------------- Fatal error: Namespace declaration statement has to be the very first statement in the script ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=66566&edit=1

« previous php.bugs (#205683) next »