codecamp

PHP8 生成器类

(PHP 5 >= 5.5.0, PHP 7, PHP 8)

简介

Generator 对象是从 generators返回的.

警告
Generator 对象不能通过 new 实例化.

类摘要

final class Generator implements Iterator {
/* 方法 */
public current(): mixed
public getReturn(): mixed
public key(): mixed
public next(): void
public rewind(): void
public send(mixed $value): mixed
public throw(Throwable $exception): mixed
public valid(): bool
public __wakeup(): void
}

参见

也可以参考 遍历对象。

目录

  • Generator::current — 返回当前产生的值
  • Generator::getReturn — 获取生成器的返回值
  • Generator::key — 返回当前产生的键
  • Generator::next — 生成器继续执行
  • Generator::rewind — 重置迭代器
  • Generator::send — 向生成器中传入一个值
  • Generator::throw — 向生成器中抛入一个异常
  • Generator::valid — 检查迭代器是否被关闭
  • Generator::__wakeup — 序列化回调


PHP8 stdClass 类
PHP8 纤程(Fiber)类
温馨提示
下载编程狮App,免费阅读超1000+编程语言教程
取消
确定