Generator 生成器类

来源:互联网 发布:java上线项目 编辑:程序博客网 时间:2024/05/18 23:25
Generator  implements Iterator  {/* 方法 */public mixed current ( void )public mixed key ( void )public void next ( void )public void rewind ( void )public mixed send ( mixed $value )public void throw ( Exception $exception )public bool valid ( void )public void __wakeup ( void )}•Generator::current — 返回当前产生的值•Generator::key — 返回当前产生的键•Generator::next — 生成器继续执行•Generator::rewind — 重置迭代器•Generator::send — 向生成器中传入一个值•Generator::throw — 向生成器中抛入一个异常•Generator::valid — 检查迭代器是否被关闭•Generator::__wakeup — 序列化回调

Consider this example:

function gen() {    echo 'start';    yield 'middle';    echo 'end';}// Initial call does not output anything$gen = gen();// Call to current() resumes the generator, thus "start" is echo'd.// Then the yield expression is hit and the string "middle" is returned// as the result of current() and then echo'd.echo $gen->current();// Execution of the generator is resumed again, thus echoing "end"$gen->next();
0 0
原创粉丝点击