|   | php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login | 
| 
 PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits              [2010-11-18 23:40 UTC] jani@php.net
 
-Package:          Feature/Change Request
+Package:          Scripting Engine problem
-Operating System: Windows 2000
+Operating System: *
-PHP Version:      Irrelevant
+PHP Version:      *
  [2013-10-27 15:22 UTC] krakjoe@php.net
 
-Status: Open
+Status: Not a bug
  [2013-10-27 15:22 UTC] krakjoe@php.net
 | |||||||||||||||||||||||||||||||||
|  Copyright © 2001-2025 The PHP Group All rights reserved. | Last updated: Fri Oct 31 17:00:02 2025 UTC | 
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