diff --git a/php/ByteBuffer.php b/php/ByteBuffer.php index 9ab9717af..9929a7df1 100644 --- a/php/ByteBuffer.php +++ b/php/ByteBuffer.php @@ -399,8 +399,13 @@ class ByteBuffer $sign = $index + (ByteBuffer::isLittleEndian() ? 3 : 0); $issigned = isset($this->_buffer[$sign]) && ord($this->_buffer[$sign]) & 0x80; - // 4294967296 = 1 << 32 = Maximum unsigned 32-bit int - return $issigned ? $result - 4294967296 : $result; + if (PHP_INT_SIZE > 4) { + // 4294967296 = 1 << 32 = Maximum unsigned 32-bit int + return $issigned ? $result - 4294967296 : $result; + } else { + // 32bit / Windows treated number as signed integer. + return $result; + } } /** diff --git a/src/idl_gen_php.cpp b/src/idl_gen_php.cpp index 2aa7e222e..2488b1d18 100644 --- a/src/idl_gen_php.cpp +++ b/src/idl_gen_php.cpp @@ -249,7 +249,13 @@ namespace php { NumToString(field.value.offset) + ");\n"; code += Indent + Indent; - code += "return $o != 0 ? $obj->init($o + $this->bb_pos, $this->bb) : "; + code += "return $o != 0 ? $obj->init("; + if (field.value.type.struct_def->fixed) + { + code += "$o + $this->bb_pos, $this->bb) : "; + } else { + code += "$this->__indirect($o + $this->bb_pos), $this->bb) : "; + } code += GenDefaultValue(field.value) + ";\n"; code += Indent + "}\n\n"; } diff --git a/tests/MyGame/Example/Monster.php b/tests/MyGame/Example/Monster.php index 94a0df7d9..6c1d34a0b 100644 --- a/tests/MyGame/Example/Monster.php +++ b/tests/MyGame/Example/Monster.php @@ -188,7 +188,7 @@ class Monster extends Table { $obj = new Monster(); $o = $this->__offset(28); - return $o != 0 ? $obj->init($o + $this->bb_pos, $this->bb) : 0; + return $o != 0 ? $obj->init($this->__indirect($o + $this->bb_pos), $this->bb) : 0; } /** @@ -214,7 +214,7 @@ class Monster extends Table { $obj = new Stat(); $o = $this->__offset(32); - return $o != 0 ? $obj->init($o + $this->bb_pos, $this->bb) : 0; + return $o != 0 ? $obj->init($this->__indirect($o + $this->bb_pos), $this->bb) : 0; } /** diff --git a/tests/monsterdata_test.json b/tests/monsterdata_test.json index 7ed39a8de..89278755e 100755 --- a/tests/monsterdata_test.json +++ b/tests/monsterdata_test.json @@ -37,6 +37,9 @@ "test1", "test2" ], + enemy: { + name: "Fred" + }, testarrayofbools:[ true, false, true ], diff --git a/tests/monsterdata_test.mon b/tests/monsterdata_test.mon index eff1e66ca..69d1d7538 100644 Binary files a/tests/monsterdata_test.mon and b/tests/monsterdata_test.mon differ diff --git a/tests/phpTest.php b/tests/phpTest.php index e91e47a1d..0afc0af7f 100644 --- a/tests/phpTest.php +++ b/tests/phpTest.php @@ -30,6 +30,10 @@ function main() // We set up the same values as monsterdata.json: $str = $fbb->createString("MyMonster"); + $name = $fbb->createString('Fred'); + \MyGame\Example\Monster::startMonster($fbb); + \MyGame\Example\Monster::addName($fbb, $name); + $enemy = \MyGame\Example\Monster::endMonster($fbb); $inv = \MyGame\Example\Monster::CreateInventoryVector($fbb, array(0, 1, 2, 3, 4)); @@ -62,6 +66,7 @@ function main() \MyGame\Example\Monster::AddTest($fbb, $mon2); \MyGame\Example\Monster::AddTest4($fbb, $test4); \MyGame\Example\Monster::AddTestarrayofstring($fbb, $testArrayOfString); + \MyGame\Example\Monster::AddEnemy($fbb, $enemy); \MyGame\Example\Monster::AddTestbool($fbb, false); $mon = \MyGame\Example\Monster::EndMonster($fbb); @@ -132,6 +137,10 @@ function test_buffer(Assert $assert, Google\FlatBuffers\ByteBuffer $bb) { $assert->strictEqual($monster->GetTestarrayofstringLength(), 2); $assert->strictEqual($monster->GetTestarrayofstring(0), 'test1'); $assert->strictEqual($monster->GetTestarrayofstring(1), 'test2'); + + $fred = $monster->getEnemy(); + $assert->Equal('Fred', $fred->getName()); + $assert->strictEqual($monster->GetTestbool(), false); }