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

inlineiterator():GeneratorIterator

@:native("throw")throwError(exception:Throwable):Dynamic