use of php.runtime.Memory in project jphp by jphp-compiler.
the class SimpleExpressionTest method testAssignDiv.
@Test
public void testAssignDiv() {
Memory memory = run("$x = 10; $x /= 2; return $x", false);
Assert.assertEquals(5, memory.toLong());
}
use of php.runtime.Memory in project jphp by jphp-compiler.
the class SimpleExpressionTest method testAssignMod.
@Test
public void testAssignMod() {
Memory memory = run("$x = 10; $x %= 3; return $x", false);
Assert.assertEquals(1, memory.toLong());
}
use of php.runtime.Memory in project jphp by jphp-compiler.
the class SimpleExpressionTest method testOr.
@Test
public void testOr() {
Memory memory = runDynamic("$x || true");
Assert.assertEquals(true, memory.toBoolean());
memory = runDynamic("$x or true");
Assert.assertEquals(true, memory.toBoolean());
}
use of php.runtime.Memory in project jphp by jphp-compiler.
the class SimpleExpressionTest method testBug119.
@Test
public void testBug119() {
Memory r = runDynamic("$val = 3; $t = '2'; return '1' . $t . (int)$val;", false);
Assert.assertEquals("123", r.toString());
}
use of php.runtime.Memory in project jphp by jphp-compiler.
the class SPLFunctions method iterator_apply.
public static long iterator_apply(Environment env, TraceInfo trace, Memory object, Memory callback, Memory args) throws Throwable {
if (expectingImplement(env, trace, 1, object, Traversable.class)) {
Invoker invoker = expectingCallback(env, trace, 2, callback);
if (invoker == null)
return 0;
if (args != null && !expecting(env, trace, 3, args, Memory.Type.ARRAY)) {
return 0;
}
ForeachIterator iterator = object.getNewIterator(env, false, false);
Memory[] values = args == null ? null : args.toValue(ArrayMemory.class).values(true);
int i = 0;
while (iterator.next()) {
if (!invoker.call(values).toBoolean())
break;
i++;
}
return i;
} else
return 0;
}
Aggregations