Bug #70884 [Opn->Fbk]: Empty() throws E_NOTICE on undefined index of class const array

From: Date: Tue, 10 Nov 2015 03:05:07 +0000
Subject: Bug #70884 [Opn->Fbk]: Empty() throws E_NOTICE on undefined index of class const array
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-197145@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=70884&edit=1

 ID:                 70884
 Updated by:         reeze@php.net
 Reported by:        info at ronin-design dot com
 Summary:            Empty() throws E_NOTICE on undefined index of class
                     const array
-Status:             Open
+Status:             Feedback
 Type:               Bug
 Package:            Class/Object related
 Operating System:   OS X 10.10.4 (14E46)
 PHP Version:        5.6.15
 Block user comment: N
 Private report:     N

 New Comment:

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.


Previous Comments:
------------------------------------------------------------------------
[2015-11-09 23:04:03] 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"


------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=70884&edit=1


Thread (3 messages)

« previous php.bugs (#197145) next »