SplQueue::dequeue

(PHP 5 >= 5.3.0)

SplQueue::dequeueDequeues a node from the queue

Description

mixed SplQueue::dequeue ( void )

Dequeues value from the top of the queue.

Note:

SplQueue::dequeue() is an alias of SplDoublyLinkedList::shift().

Parameters

This function has no parameters.

Return Values

The value of the dequeued node.

Коментарии

If the queue is empty, dequeue() will raise an 'RuntimeException' with message 'Can't shift from an empty datastructure'.
2010-01-20 22:57:28
http://php5.kiev.ua/manual/ru/splqueue.dequeue.html
<?php
$q 
= new SplQueue();
$q->setIteratorMode(SplQueue::IT_MODE_DELETE);
$q->enqueue('item 1');
$q->enqueue('item 2');
$q->enqueue('item 3');

$q->dequeue();
$q->dequeue();

foreach (
$q as $item) {
    echo 
$item;
}

//Result: item 3

$q->dequeue(); //Fatal error: Uncaught exception 'RuntimeException' 
              //with message 'Can't shift from an empty datastructure'
?>
2011-09-30 14:10:52
http://php5.kiev.ua/manual/ru/splqueue.dequeue.html
I just thought this was a fun and interesting way for lining up method calls and then calling them back-to-back. Might be useful as a basis for a transactional execution class or something.

<?php
$q 
= new SplQueue();
$q->setIteratorMode(SplQueue::IT_MODE_DELETE);

$q->enqueue(array("FooBar""foo"));
$q->enqueue(array("FooBar""bar"));
$q->enqueue(array("FooBar""msg""Hi there!"));

foreach (
$q as $task) {
  if (
count($task) > 2) {
    list(
$class$method$args) = $task;
   
$class::$method($args);
  } else {
    list(
$class$method) = $task;
   
$class::$method();
  }
}

class 
FooBar {
  public static function 
foo() { 
    echo 
"FooBar::foo() called.\n";
  }
  public static function 
bar() {
    echo 
"FooBar::bar() called.\n";
  }
  public static function 
msg($msg) {
    echo 
"$msg\n";
  }
}
?>

Results:
FooBar::foo() called.
FooBar::bar() called.
Hi there!
2013-07-06 06:30:40
http://php5.kiev.ua/manual/ru/splqueue.dequeue.html
I just thought this was a fun and interesting way for lining up method calls and then calling them back-to-back. Might be useful as a basis for a transactional execution class or something.

<?php
$q 
= new SplQueue();
$q->setIteratorMode(SplQueue::IT_MODE_DELETE);

$q->enqueue(array("FooBar""foo"));
$q->enqueue(array("FooBar""bar"));
$q->enqueue(array("FooBar""msg""Hi there!"));

foreach (
$q as $task) {
  if (
count($task) > 2) {
    list(
$class$method$args) = $task;
   
$class::$method($args);
  } else {
    list(
$class$method) = $task;
   
$class::$method();
  }
}

class 
FooBar {
  public static function 
foo() { 
    echo 
"FooBar::foo() called.\n";
  }
  public static function 
bar() {
    echo 
"FooBar::bar() called.\n";
  }
  public static function 
msg($msg) {
    echo 
"$msg\n";
  }
}
?>

Results:
FooBar::foo() called.
FooBar::bar() called.
Hi there!
2013-07-06 06:31:27
http://php5.kiev.ua/manual/ru/splqueue.dequeue.html

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