Bug #74339 [Com]: BOGUS: Fatal error: strict_types declaration must be the very first statement
| From: | everx80 at gmail dot com | Date: | Mon, 04 May 2020 18:36:25 +0000 |
| Subject: | Bug #74339 [Com]: BOGUS: Fatal error: strict_types declaration must be the very first statement | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-226917@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=74339&edit=1
ID: 74339
Comment by: everx80 at gmail dot com
Reported by: spam2 at rhsoft dot net
Summary: BOGUS: Fatal error: strict_types declaration must be
the very first statement
Status: Not a bug
Type: Bug
Package: Scripting Engine problem
Operating System: Linux
PHP Version: 7.1.3
Block user comment: N
Private report: N
New Comment:
@nikic@php.net I am sorry. After re-checking everything once more, it seems that an invisible UTF-8
character somehow snuck into the file, before the <?php
So it's actually not an issue, but quite difficult to see the reason. It would be nice if PHP
could somehow point that out, but idk if it's worth it...
Previous Comments:
------------------------------------------------------------------------
[2020-05-04 18:29:31] everx80 at gmail dot com
@nikic@php.net Here in full detail:
$ /usr/bin/php -v
PHP 7.4.5 (cli) (built: Apr 30 2020 04:42:29) ( ZTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
with Zend OPcache v7.4.5, Copyright (c), by Zend Technologies
$ cat test.php
#!/usr/bin/php
<?php declare(strict_types=1);
echo "test";
$ chmod +x test.php
$ file test.php
test.php: PHP script, UTF-8 Unicode text executable
$ ./test.php
PHP Fatal error: strict_types declaration must be the very first statement in the script in
/home/test/test.php on line 2
------------------------------------------------------------------------
[2020-05-04 17:24:14] nikic@php.net
@everx80: When you say "from cli", what exactly do you mean? Invoking a file with CLI
binary? Piping it as stdin? Entering it in interactive mode?
------------------------------------------------------------------------
[2020-05-04 17:06:02] everx80 at gmail dot com
@nikic@php.net i didn't want to open another bug if not neccesary, however with PHP 7.4.5 the
following code from cli still doesn't work and gives the same error:
#!/usr/bin/php
<?php
declare(strict_types=1);
echo "Hello World\n";
------------------------------------------------------------------------
[2019-10-07 15:04:43] nikic@php.net
@kevin at kevinlocke dot name: The stdin issue will be fixed in PHP 7.4.
------------------------------------------------------------------------
[2019-10-07 13:38:09] kevin at kevinlocke dot name
This issue also occurs when CLI scripts are read from stdin by php (e.g. for linting). For example,
if mycli.php has the following content:
#!/usr/bin/php
<?php
declare(strict_types=1);
echo "Hello World\n";
Running
php -l mycli.php prints "No syntax errors detected in mycli.php".
Running php -l < mycli.php (as some lint tools like ALE do) prints "PHP Fatal
error: strict_types declaration must be the very first statement in the script in Standard input
code on line 3".
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
https://bugs.php.net/bug.php?id=74339
--
Edit this bug report at https://bugs.php.net/bug.php?id=74339&edit=1