Bug #66566 [Asn]: Parse error when files contain shebang and NS declaration
Edit report at https://bugs.php.net/bug.php?id=66566&edit=1
ID: 66566
Updated by: willfitch@php.net
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.5.8
+PHP Version: 5.3
Assigned To: willfitch
Block user comment: N
Private report: N
New Comment:
Verified from PHP 5.3+
Previous Comments:
------------------------------------------------------------------------
[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
Thread (8 messages)