Stoner loop
Posted: Wed Nov 09, 2011 11:04 am
Lets you loop through one or two callback functions a given amount of times from the global scope.
Code: Select all
<?php
class stonerLoop {
var $calls;
var $callNum;
var $callBackOne;
var $callBackTwo;
function __construct( $numCalls, $callBackOne, $callBackTwo=NULL )
{
$this->calls = $numCalls;
$this->callBackOne = $callBackOne;
$this->callBackTwo = $callBackTwo == NULL ? $callBackOne : $callBackTwo;
$this->one();
}
function call($function)
{
$function();
}
function one()
{
$this->callNum++;
$this->call($this->callBackOne);
if( $this->callNum > $this->calls )
{
return;
}
$this->two();
}
function two()
{
$this->callNum++;
$this->call($this->callBackTwo);
if( $this->callNum > $this->calls )
{
return;
}
$this->one();
}
}
function lol()
{
echo 'LOL';
}
function haha()
{
echo 'haha';
}
new stonerLoop(10, 'lol', 'haha');
?>