Bug #66566 [Opn->Asn]: Parse error when files contain shebang and NS declaration

From: Date: Fri, 24 Jan 2014 03:35:14 +0000
Subject: Bug #66566 [Opn->Asn]: Parse error when files contain shebang and NS declaration
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-183982@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:         willfitch@php.net
 Reported by:        eric at wepay dot com
 Summary:            Parse error when files contain shebang and NS
                     declaration
-Status:             Open
+Status:             Assigned
 Type:               Bug
 Package:            Scripting Engine problem
 Operating System:   OS X, CentOS
 PHP Version:        5.5.8
-Assigned To:        
+Assigned To:        willfitch
 Block user comment: N
 Private report:     N



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)

« previous php.bugs (#183982) next »