php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #74783 php -l incorrectly reporting fatal error for strict_types
Submitted: 2017-06-19 18:47 UTC Modified: 2019-07-15 14:36 UTC
Votes:3
Avg. Score:4.3 ± 0.5
Reproduced:3 of 3 (100.0%)
Same Version:1 (33.3%)
Same OS:1 (33.3%)
From: eric at ericstrern dot com Assigned: nikic (profile)
Status: Closed Package: CGI/CLI related
PHP Version: 7.1.6 OS: MacOS 10.12.4
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: eric at ericstrern dot com
New email:
PHP Version: OS:

 

 [2017-06-19 18:47 UTC] 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

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-08-12 00:06 UTC] 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.
 [2019-07-15 14:36 UTC] nikic@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: nikic
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 03 10:01:33 2025 UTC