note 112629 added to splqueue.dequeue

From: Date: Sat, 06 Jul 2013 03:30:42 +0000
Subject: note 112629 added to splqueue.dequeue
Groups: php.notes 
Request: Send a blank email to php-notes+get-195474@lists.php.net to get a copy of this message
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! ---- Server IP: 69.147.83.199 Probable Submitter: 108.51.21.48 ---- Manual Page -- http://php.net/manual/en/splqueue.dequeue.php Edit -- https://master.php.net/note/edit/112629 Del: integrated -- https://master.php.net/note/delete/112629/integrated Del: useless -- https://master.php.net/note/delete/112629/useless Del: bad code -- https://master.php.net/note/delete/112629/bad+code Del: spam -- https://master.php.net/note/delete/112629/spam Del: non-english -- https://master.php.net/note/delete/112629/non-english Del: in docs -- https://master.php.net/note/delete/112629/in+docs Del: other reasons-- https://master.php.net/note/delete/112629 Reject -- https://master.php.net/note/reject/112629 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#195474) next »