Generator 生成器类

2017-01-13 10:54:28来源:csdn作者:q601115211人点击

Generatorimplements 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();

最新文章

123

最新摄影

微信扫一扫

第七城市微信公众平台