Bug #70884 [NEW]: Empty() throws E_NOTICE on undefined index of class const array

From: Date: Mon, 09 Nov 2015 23:04:06 +0000
Subject: Bug #70884 [NEW]: Empty() throws E_NOTICE on undefined index of class const array
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-197141@lists.php.net to get a copy of this message
From:             info at ronin-design dot com
Operating system: OS X 10.10.4 (14E46)
PHP version:      5.6.15
Package:          Class/Object related
Bug Type:         Bug
Bug description:Empty() throws E_NOTICE on undefined index of class const array

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 bug report at https://bugs.php.net/bug.php?id=70884&edit=1
-- 
Try a snapshot (PHP 5.4):   https://bugs.php.net/fix.php?id=70884&r=trysnapshot54
Try a snapshot (PHP 5.5):   https://bugs.php.net/fix.php?id=70884&r=trysnapshot55
Try a snapshot (trunk):     https://bugs.php.net/fix.php?id=70884&r=trysnapshottrunk
Fixed in SVN:               https://bugs.php.net/fix.php?id=70884&r=fixed
Fixed in release:           https://bugs.php.net/fix.php?id=70884&r=alreadyfixed
Need backtrace:             https://bugs.php.net/fix.php?id=70884&r=needtrace
Need Reproduce Script:      https://bugs.php.net/fix.php?id=70884&r=needscript
Try newer version:          https://bugs.php.net/fix.php?id=70884&r=oldversion
Not developer issue:        https://bugs.php.net/fix.php?id=70884&r=support
Expected behavior:          https://bugs.php.net/fix.php?id=70884&r=notwrong
Not enough info:            https://bugs.php.net/fix.php?id=70884&r=notenoughinfo
Submitted twice:            https://bugs.php.net/fix.php?id=70884&r=submittedtwice
register_globals:           https://bugs.php.net/fix.php?id=70884&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=70884&r=php4
Daylight Savings:           https://bugs.php.net/fix.php?id=70884&r=dst
IIS Stability:              https://bugs.php.net/fix.php?id=70884&r=isapi
Install GNU Sed:            https://bugs.php.net/fix.php?id=70884&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=70884&r=float
No Zend Extensions:         https://bugs.php.net/fix.php?id=70884&r=nozend
MySQL Configuration Error:  https://bugs.php.net/fix.php?id=70884&r=mysqlcfg



Thread (3 messages)

« previous php.bugs (#197141) next »