use of php.runtime.lang.spl.Countable in project jphp by jphp-compiler.
the class SPLFunctions method iterator_count.
public static long iterator_count(Environment env, TraceInfo trace, Memory object) {
if (expectingImplement(env, trace, 1, object, Traversable.class)) {
IObject tmp = object.toValue(ObjectMemory.class).value;
if (tmp instanceof Countable) {
return ((Countable) tmp).count(env).toLong();
} else {
ForeachIterator iterator = object.getNewIterator(env, true, false);
int i = 0;
while (iterator.next()) i++;
return i;
}
} else
return 0;
}
Aggregations