|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #66566 Parse error when files contain shebang and NS declaration
Submitted: 2014-01-24 02:23 UTC Modified: 2019-07-15 14:30 UTC
Avg. Score:3.7 ± 0.7
Reproduced:18 of 18 (100.0%)
Same Version:8 (44.4%)
Same OS:9 (50.0%)
From: eric at wepay dot com Assigned: nikic (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: * OS: *
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: eric at wepay dot com
New email:
PHP Version: OS:


 [2014-01-24 02:23 UTC] eric at wepay dot com
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

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


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2014-01-24 03:35 UTC]
-Status: Open +Status: Assigned -Assigned To: +Assigned To: willfitch
 [2014-01-24 03:54 UTC]
-PHP Version: 5.5.8 +PHP Version: 5.3
 [2014-01-24 03:54 UTC]
Verified from PHP 5.3+
 [2016-06-28 11:07 UTC]
Fixed in PHP 7
 [2016-11-29 19:09 UTC] miken32 at gmail dot com
No, this remains an issue in version 7.0.13.
 [2017-10-24 03:28 UTC]
-Status: Assigned +Status: Open -Assigned To: willfitch +Assigned To:
 [2017-10-24 03:28 UTC]
-Operating System: OS X, CentOS +Operating System: * -PHP Version: 5.3 +PHP Version: *
 [2018-03-31 17:34 UTC] cmanley at xs4all dot nl
Still an issue in PHP 7.0.27-0+deb9u1 too.
 [2019-07-15 14:30 UTC]
-Status: Open +Status: Closed -Assigned To: +Assigned To: nikic
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Fri Apr 16 15:01:24 2021 UTC