- rand: documentation ( source)
<?php
trait Randoz{
public function between0And10():int
{
return rand(0,10);
}
}
interface RndCounter
{
function randomInt():int;
function between0And10():int;
}
function create(): RndCounter
{
return new class() implements RndCounter
{
use Randoz;
function randomInt():int
{
return rand();
}
};
}
$counter = create();
echo $counter->randomInt()." - ".$counter->between0And10();