note 101038 added to splfixedarray.offsetunset

From: Date: Mon, 22 Nov 2010 16:07:37 +0000
Subject: note 101038 added to splfixedarray.offsetunset
Groups: php.notes 
Request: Send a blank email to php-notes+get-174260@lists.php.net to get a copy of this message
This function assigns NULL to the array element. Its use has no effect on count(). Whereas assigning NULL to an element will have no effect on isset(), offsetUnset() and unset() do. Whereas unsetting an element affects the behaviour of foreach() as applied to an array or an ArrayObject, it has no such effect on SplFixedArray, as demonstrated by the code below. <?php class atest extends SplFixedArray { public function fill() { for ($i = $this->count(); --$i >= 0; ) $this[$i] = $i; } public function dump() { $sep = ' '; foreach ($this as $k => $v) { echo $sep, "$k: ", (is_null($v) ? 'NULL' : $v); if (!isset($this[$k])) echo ' and unset'; $sep = ', '; } echo PHP_EOL; } } $a = new atest(3); $a->dump(); // 0: NULL and unset, 1: NULL and unset, 2: NULL and unset $a->fill(); $a->dump(); // 0: 0, 1: 1, 2: 2 $a[1] = NULL; unset($a[2]); $a->dump(); // 0: 0, 1: NULL, 2: NULL and unset ---- Server IP: 69.147.83.197 Probable Submitter: 217.43.53.84 ---- Manual Page -- http://www.php.net/manual/en/splfixedarray.offsetunset.php Edit -- https://master.php.net/note/edit/101038 Del: integrated -- https://master.php.net/note/delete/101038/integrated Del: useless -- https://master.php.net/note/delete/101038/useless Del: bad code -- https://master.php.net/note/delete/101038/bad+code Del: spam -- https://master.php.net/note/delete/101038/spam Del: non-english -- https://master.php.net/note/delete/101038/non-english Del: in docs -- https://master.php.net/note/delete/101038/in+docs Del: other reasons-- https://master.php.net/note/delete/101038 Reject -- https://master.php.net/note/reject/101038 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#174260) next »