php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #76269 Empty on constant array
Submitted: 2018-04-25 16:09 UTC Modified: 2018-04-25 16:16 UTC
From: ivanis dot kouame+php at gmail dot com Assigned: peehaa (profile)
Status: Closed Package: Reproducible crash
PHP Version: 5.6.35 OS: Linux
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: ivanis dot kouame+php at gmail dot com
New email:
PHP Version: OS:

 

 [2018-04-25 16:09 UTC] ivanis dot kouame+php at gmail dot com
Description:
------------
I try to do an array access wrapped with empty on a constant array and a notice is thrown. I expected that empty would simply return false in the case the key is not found.

Test script:
---------------
<?php
class Test
{
  const FOO = ["a" => 0, "b" => 1, "b" => 2, "d" => 3];    

  public function getTest()
  {
    $a = ["a" => 0, "b" => 1, "b" => 2, "d" => 3];
    var_dump(empty($a["not_found"]));

    $b = self::FOO;
    var_dump(empty($b["not_found"]));

    var_dump(empty(self::FOO["not_found"]));
  }
}


$a = new Test();
$a->getTest();

Expected result:
----------------
bool(true)
bool(true)
bool(true)

Actual result:
--------------
bool(true)
bool(true)
<br />
<b>Notice</b>:  Undefined index: vsqsc in <b>[...][...]</b> on line <b>9</b><br />
bool(true)


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-04-25 16:15 UTC] peehaa@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: peehaa
 [2018-04-25 16:15 UTC] peehaa@php.net
Thank you for your bug report. This issue has already been fixed
in the latest released version of PHP, which you can download at 
http://www.php.net/downloads.php

This seems to be already fixed as of 7.1 https://3v4l.org/UYg9F

Thank you for your bug report. This issue has already been fixed
in the latest released version of PHP, which you can download at 
http://www.php.net/downloads.php
 [2018-04-25 16:19 UTC] peehaa@php.net
Actually it was already fixed in 7.0
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Jul 02 17:01:35 2025 UTC