W3cubDocs

/Haxe PHP

Generator

package php

Available on php

Generator is not a Haxe Iterable. It can be iterated one time only. Unfortunately Haxe does not know that in PHP generators may have no return expression or return value with any type of value. Use return null or untyped cast to workaround this issue:

function generatorWithoutReturn():Generator {
	php.Syntax.yield(1);
	return null;
}

function generatorWithReturn():Generator {
	php.Syntax.yield(1);
	return cast "hello";
}

var g = generatorWithReturn();
for(i in g) {
	trace(i);
}
trace(g.getReturn()); // "hello"

See also:

Methods

current():Dynamic

getReturn():Dynamic

inlineiterator():GeneratorIterator

key():Dynamic

next():Void

rewind():Void

send(value:Dynamic):Dynamic

throwError(exception:Throwable):Dynamic

valid():Bool

© 2005–2020 Haxe Foundation
Licensed under a MIT license.
https://api.haxe.org/php/Generator.html