SplDoublyLinkedList::getIteratorMode

(PHP 5 >= 5.3.0)

SplDoublyLinkedList::getIteratorModeВозвращает режим итерации

Описание

int SplDoublyLinkedList::getIteratorMode ( void )

Список параметров

У этой функции нет параметров.

Возвращаемые значения

Возвращает различные режимы и флаги, влияющие на итерацию.

Коментарии

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. 

The way you SHOULD do it (at least until they add any more options):

Basically, you should just check the non-zero flags (LIFO(2) and DELETE(1)).  Since it's an either/or situation within the pairs, this should be able to help you figure out the separate mode pieces an instance has been set to.

example:

<?php
$l 
= new SPLDoublyLinkedList();
$l->setIteratorMode(SplDoublyLinkedList::IT_MODE_FIFO SplDoublyLinkedList::IT_MODE_DELETE);

$mode $l->getIteratorMode();

$isLIFO = ($mode SplDoublyLinkedList::IT_MODE_LIFO) == SplDoublyLinkedList::IT_MODE_LIFO;

$isDELETE = ($mode SplDoublyLinkedList::IT_MODE_DELETE) == SplDoublyLinkedList::IT_MODE_DELETE;
?>

Hope this can help someone.
2011-12-11 12:32:57
http://php5.kiev.ua/manual/ru/spldoublylinkedlist.getiteratormode.html

    Поддержать сайт на родительском проекте КГБ