Bug #74783 [NEW]: php -l incorrectly reporting fatal error for strict_types

From: Date: Mon, 19 Jun 2017 18:47:57 +0000
Subject: Bug #74783 [NEW]: php -l incorrectly reporting fatal error for strict_types
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-209593@lists.php.net to get a copy of this message
From: eric at ericstrern dot com Operating system: MacOS 10.12.4 PHP version: 7.1.6 Package: CGI/CLI related Bug Type: Bug Bug description:php -l incorrectly reporting fatal error for strict_types Description: ------------ When using php -l to syntax check a file with stdin (which is how some editors live-check an unsaved file), an error about strict_types declaration not being on the first line is erroneously returned if the file starts with a shebang. This does not happen when passing the filename in directly. I discovered this using Vim8 with the ale linting plugin (w0rp/ale), but it's easily reproduced directly on the command line. Test script: --------------- example.php: ``` #!/usr/bin/env php <?php declare(strict_types=1); echo 'hello world'; ``` Expected result: ---------------- When linting stdin, the presence of a shebang should not trigger a false positive error: $ php -l example.php No syntax errors detected in example.php $ php -l -- < example.php No syntax errors detected in example.php Actual result: -------------- A false positive is triggered: $ php -l example.php No syntax errors detected in example.php $ php -l -- < example.php PHP Fatal error: strict_types declaration must be the very first statement in the script in - on line 3 Executing the file also works fine, as expected: $ ./example.php hello world -- Edit bug report at https://bugs.php.net/bug.php?id=74783&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=74783&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=74783&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=74783&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=74783&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=74783&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=74783&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=74783&r=needscript Try newer version: https://bugs.php.net/fix.php?id=74783&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=74783&r=support Expected behavior: https://bugs.php.net/fix.php?id=74783&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=74783&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=74783&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=74783&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=74783&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=74783&r=dst IIS Stability: https://bugs.php.net/fix.php?id=74783&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=74783&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=74783&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=74783&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=74783&r=mysqlcfg

« previous php.bugs (#209593) next »