首页 > PHP教程 > PHP预定义接口的使用

PHP 生成器类和Closure类

生成器提供了一种更容易的方法来实现简单的对象迭代,相比较定义类实现 Iterator 接口的方式,性能开销和复杂性大大降低。Closure 类用于代表匿名函数的类。

生成器类 

生成器提供了一种更容易的方法来实现简单的对象迭代,相比较定义类实现 Iterator 接口的方式,性能开销和复杂性大大降低。

类摘要 

Generator 对象是从 generators返回的

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 )

}

 

Closure 类

用于代表 匿名函数 的类

类摘要

Closure {

/* 方法 */

__construct ( void ) //用于禁止实例化的构造函数

public static Closure bind ( Closure $closure , object $newthis [, mixed $newscope = 'static' ] ) //复制一个闭包,绑定指定的$this对象和类作用域

public Closure bindTo ( object $newthis [, mixed $newscope = 'static' ] ) //复制当前闭包对象,绑定指定的$this对象和类作用域

}

PHP历史版本

关闭
感谢您的支持,我会继续努力!
扫码打赏,建议金额1-10元


提醒:打赏金额将直接进入对方账号,无法退款,请您谨慎操作。