- rand: documentation ( source)
<?php
class Testing {
private $value = 0;
public function incrementBy1() {
$this->value ++;
if (rand(1, 9)) {
return null;
}
return $this;
}
public function output() {
echo "value: " . $this->value;
}
}
$test = new Testing;
$test->incrementBy1()->incrementBy1()->incrementBy1()->output();