Bug #77561 [Com]: PHAR bootstrap script with shebang and strict types does not work
| From: | spam2 at rhsoft dot net | Date: | Tue, 05 Feb 2019 16:28:22 +0000 |
| Subject: | Bug #77561 [Com]: PHAR bootstrap script with shebang and strict types does not work | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-219373@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=77561&edit=1
ID: 77561
Comment by: spam2 at rhsoft dot net
Reported by: sebastian@php.net
Summary: PHAR bootstrap script with shebang and strict types
does not work
Status: Open
Type: Bug
Package: PHAR related
Operating System: Irrelevant
PHP Version: 7.3.1
Block user comment: N
Private report: N
New Comment:
yeah that would solve this problem, in the example below 'auth.php' is a NOOP in case
PHP_SAPI === 'cli' and when called from the webserver it verifies the userlogin and stops
with a loginform
that's in fact a cronjob file and the web-call is for "i need that damned task now and not
in 5 minutes" and i have dozens of examples where this makes sense
#!/usr/bin/php
<?php declare(strict_types=1);
require __DIR__ . '/../../auth.php';
$cl_api->worker->import();
?>
Previous Comments:
------------------------------------------------------------------------
[2019-02-05 16:10:04] nikic@php.net
I just looked into this a bit. Shebang lines are currently handled by the SAPI layer, by stripping
it off before it even reaches the lexer. The CLI SAPI always does this, while the CGI SAPI has a
default-enabled ini option for it (cgi.check_shebang_line), that I learned about today. Other SAPIs
don't have this option.
I think we'll want to move the shebang stripping into the lexer, but I'm not sure if we
can get away with unconditionally enabling it.
------------------------------------------------------------------------
[2019-02-04 00:20:59] spam2 at rhsoft dot net
but for cli scripts exists an inconsistent hack für shebangs and the way it works makes it as
example imposible write a strict-typed script which works with different SAPI's
------------------------------------------------------------------------
[2019-02-04 00:02:41] cmb@php.net
> the topic is about <?php declare(strict_types=1); and you come up with a simple missing the
> point?
My point is that PHP sees the whole file as a single script, and that everything outside of <?php
?> is simply ârewrittenâ to be echoed. E.g.
#!/usr/bin/env php
<?php declare(strict_types=1);
is compiled the same as
<?php
echo "#!/usr/bin/env php\n";
declare(strict_types=1);
So, declare is *not* the âvery first statement in the scriptâ.
------------------------------------------------------------------------
[2019-02-03 19:24:04] phpbugs at olemartin dot org
I agree with @cmb that the example with arbitrary content before the start tag should produce the
error. However, it's quite a gotcha that a shebang is stripped in some cases (when executed by
the cli) but not others (when included). Same should go with a BOM (and other magic numbers?).
Since there are partial support for shebangs, that support should be made consistent.
------------------------------------------------------------------------
[2019-02-03 18:34:55] spam2 at rhsoft dot net
@cmb seriously?
the topic is about <?php declare(strict_types=1); and you come up with a simple missing the
point?
[harry@srv-rhsoft:/downloads]$ cat test.php
foo
<?php declare(strict_types=1);
echo 'bar';
[harry@srv-rhsoft:/downloads]$ php test.php
Fatal error: strict_types declaration must be the very first statement in the script in
/mnt/data/downloads/test.php on line 2
[harry@srv-rhsoft:/downloads]$
------------------------------------------------------------------------
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=77561
--
Edit this bug report at https://bugs.php.net/bug.php?id=77561&edit=1