php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #70884 Empty() throws E_NOTICE on undefined index of class const array
Submitted: 2015-11-09 23:04 UTC Modified: 2015-11-22 04:22 UTC
From: info at ronin-design dot com Assigned:
Status: No Feedback Package: Class/Object related
PHP Version: 5.6.15 OS: OS X 10.10.4 (14E46)
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 this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: info at ronin-design dot com
New email:
PHP Version: OS:

 

 [2015-11-09 23:04 UTC] info at ronin-design dot com
Description:
------------
Empty() function throws E_NOTICE "Notice: Undefined index" when checking a class constant of type ARRAY for non-existent element. However, isset() works as expected.

Test script:
---------------
class Test
{
  private $obj;
  const MAP = ['testKey' => 'test'];
  
  function __construct()
  {
    $this->obj       = new \stdClass();
    $this->obj->test = "testObject";
  }

  public function isKey($name = 'testKey') {
    var_dump(empty($this->obj->{static::MAP[$name]}));
    var_dump(empty($this->obj->$name));
  }
}

Expected result:
----------------
Expect to see var_dump() return boolean result of empty() WITHOUT E_NOTICE generation.

Actual result:
--------------
var_dump() correctly returns result of empty(), but also generates E_NOTICE "Notice: Undefined index"

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-11-10 03:05 UTC] reeze@php.net
-Status: Open +Status: Feedback
 [2015-11-10 03:05 UTC] reeze@php.net
Not enough information was provided for us to be able
to handle this bug. Please re-read the instructions at
http://bugs.php.net/how-to-report.php

If you can provide more information, feel free to add it
to this bug and change the status back to "Open".

Thank you for your interest in PHP.


https://3v4l.org/Ue5Cj  There is no Notice.  please provider more information.
 [2015-11-22 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: Wed Apr 24 03:01:29 2024 UTC