note 106841 added to spldoublylinkedlist.getiteratormode
| From: | gregorypatmore at gmail dot com | Date: | Sun, 11 Dec 2011 18:32:57 +0000 |
| Subject: | note 106841 added to spldoublylinkedlist.getiteratormode | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-185020@lists.php.net to get a copy of this message | ||
I think it should be noted that the IT_MODE_* constants are defined inside the class as:
IT_MODE_LIFO => int(2)
IT_MODE_FIFO => int(0)
IT_MODE_DELETE => int(1)
IT_MODE_KEEP => int(0)
With the FIFO and KEEP flags both defined as zero, you can run into an ambiguity when trying to
discern what modes have been activated when trying to use bitwise deduction as one might be lead to
believe considering the bitwise way you set the iterator mode (at least in v5.3.5, haven't
tested any others).
Consider this example:
<?php
$l = new SPLDoublyLinkedList();
$l->setIteratorMode(SplDoublyLinkedList::IT_MODE_FIFO | SplDoublyLinkedList::IT_MODE_DELETE);
$mode = $l->getIteratorMode(); #int(1)
var_dump(($mode & SplDoublyLinkedList::IT_MODE_FIFO) == SplDoublyLinkedList::IT_MODE_FIFO);
#outputs true
var_dump(($mode & SplDoublyLinkedList::IT_MODE_LIFO) == SplDoublyLinkedList::IT_MODE_LIFO);
#outputs false
var_dump(($mode & SplDoublyLinkedList::IT_MODE_DELETE) == SplDoublyLinkedList::IT_MODE_DELETE);
#outputs true
var_dump(($mode & SplDoublyLinkedList::IT_MODE_KEEP) == SplDoublyLinkedList::IT_MODE_KEEP);
#outputs true (huh?!)
?>
Regardless of whatever the getIteratorMode tells you, the object DOES correctly honor the
configuration that was set as far as I can tell.
Hope this can help someone.
----
Server IP: 64.71.164.2
Probable Submitter: 108.50.197.183
----
Manual Page -- http://www.php.net/manual/en/spldoublylinkedlist.getiteratormode.php
Edit -- https://master.php.net/note/edit/106841
Del: integrated -- https://master.php.net/note/delete/106841/integrated
Del: useless -- https://master.php.net/note/delete/106841/useless
Del: bad code -- https://master.php.net/note/delete/106841/bad+code
Del: spam -- https://master.php.net/note/delete/106841/spam
Del: non-english -- https://master.php.net/note/delete/106841/non-english
Del: in docs -- https://master.php.net/note/delete/106841/in+docs
Del: other reasons-- https://master.php.net/note/delete/106841
Reject -- https://master.php.net/note/reject/106841
Search -- https://master.php.net/manage/user-notes.php