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

From: Date: Mon, 15 Jul 2019 14:36:53 +0000
Subject: Bug #74783 [Opn->Csd]: php -l incorrectly reporting fatal error for strict_types
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-221791@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: nikic@php.net Reported by: eric at ericstrern dot com Summary: php -l incorrectly reporting fatal error for strict_types -Status: Open +Status: Closed Type: Bug Package: CGI/CLI related Operating System: MacOS 10.12.4 PHP Version: 7.1.6 -Assigned To: +Assigned To: nikic Block user comment: N Private report: N New Comment: Fixed by https://github.com/php/php-src/commit/c5f1b384b591009310370f0b06b10868d2d62741 for 7.4. Previous Comments: ------------------------------------------------------------------------ [2017-08-12 00:06:38] ajf@php.net 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. ------------------------------------------------------------------------ [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 (#221791) next »