Bug #66566 [Opn->Csd]: Parse error when files contain shebang and NS declaration
| From: | nikic@php.net | Date: | Mon, 15 Jul 2019 14:30:54 +0000 |
| Subject: | Bug #66566 [Opn->Csd]: Parse error when files contain shebang and NS declaration | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-221789@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
Updated by: nikic@php.net
Reported by: eric at wepay dot com
Summary: Parse error when files contain shebang and NS
declaration
-Status: Open
+Status: Closed
Type: Bug
Package: Scripting Engine problem
Operating System: *
PHP Version: *
-Assigned To:
+Assigned To: nikic
Block user comment: N
Private report: N
New Comment:
Fixed by https://github.com/php/php-src/commit/c5f1b384b591009310370f0b06b10868d2d62741
for 7.4.
Previous Comments:
------------------------------------------------------------------------
[2018-03-31 17:34:59] cmanley at xs4all dot nl
Still an issue in PHP 7.0.27-0+deb9u1 too.
------------------------------------------------------------------------
[2016-11-29 19:09:59] miken32 at gmail dot com
No, this remains an issue in version 7.0.13.
------------------------------------------------------------------------
[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