php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #77867 PHP silently kills itself when referencing an invalid array key in a constant
Submitted: 2019-04-09 07:45 UTC Modified: 2019-04-28 04:22 UTC
From: mcpe4life62 at gmail dot com Assigned: cmb (profile)
Status: No Feedback Package: *General Issues
PHP Version: 7.2.17 OS: Windows 10
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: mcpe4life62 at gmail dot com
New email:
PHP Version: OS:

 

 [2019-04-09 07:45 UTC] 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.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2019-04-09 07:55 UTC] nikic@php.net
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.
 [2019-04-09 08:31 UTC] cmb@php.net
-Package: Compile Failure +Package: *General Issues
 [2019-04-18 07:25 UTC] cmb@php.net
-Status: Open +Status: Feedback -Assigned To: +Assigned To: cmb
 [2019-04-18 07:25 UTC] cmb@php.net
Thank you for this bug report. To properly diagnose the problem, we
need a backtrace to see what is happening behind the scenes. To
find out how to generate a backtrace, please read
http://bugs.php.net/bugs-generating-backtrace.php for *NIX and
http://bugs.php.net/bugs-generating-backtrace-win32.php for Win32

Once you have generated a backtrace, please submit it to this bug
report and change the status back to "Open". Thank you for helping
us make PHP better.
 [2019-04-28 04:22 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 16 19:01:31 2024 UTC