- array_shift: documentation ( source)
<?php
class Dummy {
public $input;
function __construct($input = array(1,2,3)) {
$this->input = $input;
}
function run($logged)
{
foreach($this->input as $key=>$value)
{
echo $value . " " .$logged."\n\n";
if($value == 2 && $logged == false) throw new Exception('hello exception');
array_shift($this->input);
}
}
}
function retry(Dummy $dum, $logged = false)
{
try {
echo "dum start run";
$dum->run($logged);
echo "dum end run";
} catch(Exception $e)
{
// solve the exception
if(!$logged)
$logged = true;
echo "dum retry";
retry($dum, $logged);
echo "dum end retry";
}
}
$dum = new Dummy;
retry($dum, false);