From: danielc at analysisandsolutions dot com
Operating system: Windows 2000
PHP version: Irrelevant
PHP Bug Type: Zend Engine 2 problem
Bug description: undefined notices via unset()
Description:
------------
unset() acts inconsistently when acting upon array keys that don't exist.
In some cases it throws Notices about "Undefined index" "Undefined
variable" and "Undefined property."
The behavior varies depending on
a) the dimension of the array trying to be unset
b) whether the array is set
c) if the unset() call is in a class
d) the version of PHP being used
Reproduce code:
---------------
<?php
class test {
var $Array2 = array();
function test() {
unset($this->Nada); // no problem
unset($this->Array1['one:one']); // 4.3.3: Undefined property
// 500b2: no problem
unset($this->Array1['one:two'][1]); // 4.3.3: Undefined property
// 500b2: no problem
unset($this->Array2['two:one']); // no problem
unset($this->Array2['two:two'][1]); // Undefined index
unset($Nada); // no problem
unset($Array3['three:one']); // Undefined variable
unset($Array3['three:two'][1]); // Undefined variable
$Array4 = array();
unset($Array4['four:one']); // no problem
unset($Array4['four:two'][1]); // Undefined index
}
}
$test1 = new test();
unset($Nada); // no problem
unset($Array5['five:one']); // Undefined variable
unset($Array5['five:two'][1]); // Undefined variable
$Array6 = array();
unset($Array6['six:one']); // no problem
unset($Array6['six:two'][1]); // Undefined index
?>
Expected result:
----------------
No notices at all.
Considering no notice was produced on a non-existant scalar, I expected
the same behavior when trying to unset various arrays, regardless of where
the unset() all is made.
Actual result:
--------------
PHP 4.3.3
Notice: Undefined property: Array1 in t.php on line 12
Notice: Undefined property: Array1 in t.php on line 13
Notice: Undefined index: two:two in t.php on line 16
Notice: Undefined variable: Array3 in t.php on line 20
Notice: Undefined variable: Array3 in t.php on line 21
Notice: Undefined index: four:two in t.php on line 25
Notice: Undefined variable: Array5 in t.php on line 33
Notice: Undefined variable: Array5 in t.php on line 34
Notice: Undefined index: six:two in t.php on line 38
PHP 500b2-dev 200310010230
Notice: Undefined index: two:two in t.php on line 16
Notice: Undefined variable: Array3 in t.php on line 20
Notice: Undefined variable: Array3 in t.php on line 21
Notice: Undefined index: four:two in t.php on line 25
Notice: Undefined variable: Array5 in t.php on line 33
Notice: Undefined variable: Array5 in t.php on line 34
Notice: Undefined index: six:two in t.php on line 38
--
Edit bug report at http://bugs.php.net/?id=25826&edit=1
--
Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=25826&r=trysnapshot4
Try a CVS snapshot (php5): http://bugs.php.net/fix.php?id=25826&r=trysnapshot5
Fixed in CVS: http://bugs.php.net/fix.php?id=25826&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=25826&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=25826&r=needtrace
Try newer version: http://bugs.php.net/fix.php?id=25826&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=25826&r=support
Expected behavior: http://bugs.php.net/fix.php?id=25826&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=25826&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=25826&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=25826&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=25826&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=25826&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=25826&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=25826&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=25826&r=float