Example #1
0
<?php

class A
{
    public function gen()
    {
        var_dump($this);
        (yield 1);
        (yield 2);
        (yield 3);
    }
    public static function sgen()
    {
        var_dump(get_called_class());
        (yield 4);
        (yield 5);
        (yield 6);
    }
}
$a = new A();
foreach ($a->gen() as $num) {
    var_dump($num);
}
foreach (A::sgen() as $num) {
    var_dump($num);
}
Example #2
0
<?php

class A
{
    public function gen($a, $b)
    {
        (yield $a);
        (yield $b);
    }
}
$x = new A();
$x->cache_gen = $x->gen('a', 'b');
foreach ($x->cache_gen as $v) {
    var_dump($v);
}
apc_store('key', $x);
$y = apc_fetch('key');
var_dump($y->cache_gen);
Example #3
0
        $class = get_called_class();
        (yield $class);
    }
    public function foo()
    {
        return self::gen();
    }
}
class B extends A
{
}
function t($x)
{
    foreach ($x as $v) {
        var_dump($v);
    }
}
t(B::sgen());
t(B::sfoo());
t(A::sgen());
t(A::sfoo());
t(B::gen());
t(B::foo());
t(A::gen());
t(A::foo());
$b = new B();
t($b->gen());
t($b->foo());
$a = new A();
t($a->gen());
t($a->foo());