PHP 8.5.0 Alpha 4 available for testing

Voting

: seven minus zero?
(Example: nine)

The Note You're Voting On

mark at bull-roarer dot com
12 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.

<?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!

<< Back to user notes page

To Top