PHP: Hypertext Preprocessor (original) (raw)
SplQueue::dequeue
(PHP 5 >= 5.3.0, PHP 7, PHP 8)
SplQueue::dequeue — Dequeues a node from the queue
Parameters
This function has no parameters.
Return Values
The value of the dequeued node.
Found A Problem?
15 years ago
If the queue is empty, dequeue() will raise an 'RuntimeException' with message 'Can't shift from an empty datastructure'.
11 years ago
`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.
q−>setIteratorMode(SplQueue::ITMODEDELETE);q->setIteratorMode(SplQueue::IT_MODE_DELETE);q−>setIteratorMode(SplQueue::ITMODEDELETE);q->enqueue(array("FooBar", "foo")); $q->enqueue(array("FooBar", "bar")); $q->enqueue(array("FooBar", "msg", "Hi there!")); foreach ( qasq as qastask) { if (count($task) > 2) { list($class, method,method, method,args) = task;<spanclass="katex"><spanclass="katex−mathml"><mathxmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>c</mi><mi>l</mi><mi>a</mi><mi>s</mi><mi>s</mi><mo>:</mo><mo>:</mo></mrow><annotationencoding="application/x−tex">class::</annotation></semantics></math></span><spanclass="katex−html"aria−hidden="true"><spanclass="base"><spanclass="strut"style="height:0.6944em;"></span><spanclass="mordmathnormal">c</span><spanclass="mordmathnormal"style="margin−right:0.01968em;">l</span><spanclass="mordmathnormal">a</span><spanclass="mordmathnormal">ss</span><spanclass="mspace"style="margin−right:0.2778em;"></span><spanclass="mrel">::</span></span></span></span>method(task; <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>c</mi><mi>l</mi><mi>a</mi><mi>s</mi><mi>s</mi><mo>:</mo><mo>:</mo></mrow><annotation encoding="application/x-tex">class::</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.6944em;"></span><span class="mord mathnormal">c</span><span class="mord mathnormal" style="margin-right:0.01968em;">l</span><span class="mord mathnormal">a</span><span class="mord mathnormal">ss</span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">::</span></span></span></span>method(task;<spanclass="katex"><spanclass="katex−mathml"><mathxmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>c</mi><mi>l</mi><mi>a</mi><mi>s</mi><mi>s</mi><mo>:</mo><mo>:</mo></mrow><annotationencoding="application/x−tex">class::</annotation></semantics></math></span><spanclass="katex−html"aria−hidden="true"><spanclass="base"><spanclass="strut"style="height:0.6944em;"></span><spanclass="mordmathnormal">c</span><spanclass="mordmathnormal"style="margin−right:0.01968em;">l</span><spanclass="mordmathnormal">a</span><spanclass="mordmathnormal">ss</span><spanclass="mspace"style="margin−right:0.2778em;"></span><spanclass="mrel">::</span></span></span></span>method(args); } else { list($class, method)=method) = method)=task; class::class::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!
`
13 years ago
`<?php
$q = new SplQueue();
$q->setIteratorMode(SplQueue::IT_MODE_DELETE);
$q->enqueue('item 1');
$q->enqueue('item 2'); q−>enqueue(′item3′);q->enqueue('item 3');q−>enqueue(′item3′);q->dequeue();
$q->dequeue();
foreach (
qasq as qasitem) {
echo $item;
}//Result: item 3$q->dequeue(); //Fatal error: Uncaught exception 'RuntimeException'
//with message 'Can't shift from an empty datastructure'
?>`
11 years ago
`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.
q−>setIteratorMode(SplQueue::ITMODEDELETE);q->setIteratorMode(SplQueue::IT_MODE_DELETE);q−>setIteratorMode(SplQueue::ITMODEDELETE);q->enqueue(array("FooBar", "foo")); $q->enqueue(array("FooBar", "bar")); $q->enqueue(array("FooBar", "msg", "Hi there!")); foreach ( qasq as qastask) { if (count($task) > 2) { list($class, method,method, method,args) = task;<spanclass="katex"><spanclass="katex−mathml"><mathxmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>c</mi><mi>l</mi><mi>a</mi><mi>s</mi><mi>s</mi><mo>:</mo><mo>:</mo></mrow><annotationencoding="application/x−tex">class::</annotation></semantics></math></span><spanclass="katex−html"aria−hidden="true"><spanclass="base"><spanclass="strut"style="height:0.6944em;"></span><spanclass="mordmathnormal">c</span><spanclass="mordmathnormal"style="margin−right:0.01968em;">l</span><spanclass="mordmathnormal">a</span><spanclass="mordmathnormal">ss</span><spanclass="mspace"style="margin−right:0.2778em;"></span><spanclass="mrel">::</span></span></span></span>method(task; <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>c</mi><mi>l</mi><mi>a</mi><mi>s</mi><mi>s</mi><mo>:</mo><mo>:</mo></mrow><annotation encoding="application/x-tex">class::</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.6944em;"></span><span class="mord mathnormal">c</span><span class="mord mathnormal" style="margin-right:0.01968em;">l</span><span class="mord mathnormal">a</span><span class="mord mathnormal">ss</span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">::</span></span></span></span>method(task;<spanclass="katex"><spanclass="katex−mathml"><mathxmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>c</mi><mi>l</mi><mi>a</mi><mi>s</mi><mi>s</mi><mo>:</mo><mo>:</mo></mrow><annotationencoding="application/x−tex">class::</annotation></semantics></math></span><spanclass="katex−html"aria−hidden="true"><spanclass="base"><spanclass="strut"style="height:0.6944em;"></span><spanclass="mordmathnormal">c</span><spanclass="mordmathnormal"style="margin−right:0.01968em;">l</span><spanclass="mordmathnormal">a</span><spanclass="mordmathnormal">ss</span><spanclass="mspace"style="margin−right:0.2778em;"></span><spanclass="mrel">::</span></span></span></span>method(args); } else { list($class, method)=method) = method)=task; class::class::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!
`