Search in sources :

Example 6 with StdClass

use of php.runtime.lang.StdClass in project jphp by jphp-compiler.

the class JsonFunctionsTest method testObjectJsonDecode.

@Test
public void testObjectJsonDecode() {
    Memory r = JsonFunctions.json_decode(env, "{\"x\":100, \"y\":500}");
    assertTrue(r.instanceOf(StdClass.class));
    StdClass stdClass = r.toObject(StdClass.class);
    assertEquals(2, stdClass.getProperties().size());
    assertEquals(100, stdClass.getProperties().valueOfIndex("x").toLong());
    assertEquals(500, stdClass.getProperties().valueOfIndex("y").toLong());
}
Also used : Memory(php.runtime.Memory) StdClass(php.runtime.lang.StdClass) Test(org.junit.Test)

Example 7 with StdClass

use of php.runtime.lang.StdClass in project jphp by jphp-compiler.

the class ArrayMemory method toObject.

@Override
public Memory toObject(Environment env) {
    StdClass stdClass = new StdClass(env);
    ArrayMemory props = stdClass.getProperties();
    ForeachIterator iterator = getNewIterator(env, false, false);
    while (iterator.next()) {
        props.refOfIndex(null, iterator.getMemoryKey()).assign(iterator.getValue());
    }
    return new ObjectMemory(stdClass);
}
Also used : ForeachIterator(php.runtime.lang.ForeachIterator) StdClass(php.runtime.lang.StdClass)

Aggregations

StdClass (php.runtime.lang.StdClass)7 Test (org.junit.Test)4 Memory (php.runtime.Memory)3 ArrayMemory (php.runtime.memory.ArrayMemory)2 ObjectMemory (php.runtime.memory.ObjectMemory)2 Map (java.util.Map)1 ForeachIterator (php.runtime.lang.ForeachIterator)1 DoubleMemory (php.runtime.memory.DoubleMemory)1 StringMemory (php.runtime.memory.StringMemory)1