note 112630 added to splqueue.dequeue

From: Date: Sat, 06 Jul 2013 03:31:29 +0000
Subject: note 112630 added to splqueue.dequeue
Groups: php.notes 
Request: Send a blank email to php-notes+get-195475@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/112630 Del: integrated -- https://master.php.net/note/delete/112630/integrated Del: useless -- https://master.php.net/note/delete/112630/useless Del: bad code -- https://master.php.net/note/delete/112630/bad+code Del: spam -- https://master.php.net/note/delete/112630/spam Del: non-english -- https://master.php.net/note/delete/112630/non-english Del: in docs -- https://master.php.net/note/delete/112630/in+docs Del: other reasons-- https://master.php.net/note/delete/112630 Reject -- https://master.php.net/note/reject/112630 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#195475) next »