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

From: Date: Sat, 12 Aug 2017 00:06:39 +0000
Subject: Bug #74783 [Opn]: php -l incorrectly reporting fatal error for strict_types
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-210619@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=74783&edit=1 ID: 74783 Updated by: ajf@php.net Reported by: eric at ericstrern dot com Summary: php -l incorrectly reporting fatal error for strict_types Status: Open Type: Bug Package: CGI/CLI related Operating System: MacOS 10.12.4 PHP Version: 7.1.6 Block user comment: N Private report: N New Comment: The shebang line isn't ignored by PHP for stdin (it will be echo'd to output), e.g.: $ php #!/bin/sh <?php echo "foo\n"; #!/bin/sh foo This is probably why the shebang line isn't ignored for linting, either. I'm not sure this is a bug. Previous Comments: ------------------------------------------------------------------------ [2017-06-19 18:47:55] eric at ericstrern dot com 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 this bug report at https://bugs.php.net/bug.php?id=74783&edit=1

« previous php.bugs (#210619) next »