Bug #77867 [Opn]: PHP silently kills itself when referencing an invalid array key in a constant
| From: | nikic@php.net | Date: | Tue, 09 Apr 2019 07:55:52 +0000 |
| Subject: | Bug #77867 [Opn]: PHP silently kills itself when referencing an invalid array key in a constant | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-220376@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=77867&edit=1
ID: 77867
Updated by: nikic@php.net
Reported by: mcpe4life62 at gmail dot com
Summary: PHP silently kills itself when referencing an
invalid array key in a constant
Status: Open
Type: Bug
Package: Compile Failure
Operating System: Windows 10
PHP Version: 7.2.17
Block user comment: N
Private report: N
New Comment:
I can't reproduce this on Linux: https://3v4l.org/Mnk96
I also checked that it works with opcache loaded and that no valgrind warnings are triggered.
Previous Comments:
------------------------------------------------------------------------
[2019-04-09 07:45:55] mcpe4life62 at gmail dot com
Description:
------------
Adding a class / interface constant that references to another constant via an array key that's
non-existent kills the PHP process silently. (without invoking die() or exit())
There are no error messages thrown, nor a warning, or anything. PHP just dies.
There are two different results on two different scenarios.
If this bug was done on an interface, PHP silently kills itself, as mentioned for several times.
If this bug was done on a class, PHP Freezes silently and refuses to do anything. I've only
tested this for a few minutes, I don't know if it un-freezes and exits after a while.
Due to no error messages are being displayed, this made debugging it a bit tricky at first. It took
me quite a few minutes before finding out that it was an invalid array key access. Even while
I'm using PHPStorm (the class constant 'ARRAY_1' is an empty array), the erroneous
code does not get pointed out or highlighted.
Test script:
---------------
// Only use one of these to get different results.
// Insta-kill
interface BrokenInterface {
// this can be anything... even null. just with a non-existent key
public const ARRAY_1 = [];
public const ARRAY_2 = [
self::ARRAY_1["nonExistentKey"]
];
}
class UseThisClass implements BrokenInterface {}
(new UseThisClass());
// Freeze
class BrokenClass {
// this can be anything... even null. just with a non-existent key
public const ARRAY_1 = [];
public const ARRAY_2 = [
self::ARRAY_1["nonExistentKey"]
];
}
(new BrokenClass());
Expected result:
----------------
A Compile Error should be thrown.
Actual result:
--------------
PHP Silently shuts down without any warning or error message.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=77867&edit=1