Search in sources :

Example 1 with Countable

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;
}
Also used : Countable(php.runtime.lang.spl.Countable) ForeachIterator(php.runtime.lang.ForeachIterator) IObject(php.runtime.lang.IObject) ObjectMemory(php.runtime.memory.ObjectMemory)

Aggregations

ForeachIterator (php.runtime.lang.ForeachIterator)1 IObject (php.runtime.lang.IObject)1 Countable (php.runtime.lang.spl.Countable)1 ObjectMemory (php.runtime.memory.ObjectMemory)1