Skip to content

Commit 0fc66d9

Browse files
committed
Properly initialize Tarantool instance properties
The proper initialization is important for correct work of an inherited class. I cannot provide exact description what was broken and becomes right, but at least the test case with inherited class with a property starts to work correctly. Some online materials strongly suggest to call object_properties_init() function in a create_object handler, see [1], [2], [3]. The problem was catched at the existing test suite on mocking tests when phpunit was updated to 6.5.14 (now it is 4.8.24) and appropriate changes were made for the tests (say, using of createMock() instead of getMock()). So this commit is prerequisite to run the test suite on more fresh phpunit, which is necessary to test the connector on php-7.1+. The changes for php-7.1+ will land in future commits. It seems the problem was introduced in [4]. [1]: https://wiki.php.net/internals/engine/objects [2]: http://www.phpinternalsbook.com/php5/classes_objects/custom_object_storage.html [3]: https://phabricator.wikimedia.org/T59292 [4]: 9f5a282 ('updated PHP7 implementation') Fixes #135.
1 parent a8e31f3 commit 0fc66d9

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

src/tarantool.c

+1
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,7 @@ static zend_object *tarantool_create(zend_class_entry *entry) {
391391
obj = (tarantool_object *)pecalloc(1, sizeof(tarantool_object) +
392392
sizeof(zval) * (entry->default_properties_count - 1), 0);
393393
zend_object_std_init(&obj->zo, entry);
394+
object_properties_init(&obj->zo, entry);
394395
obj->zo.handlers = &tarantool_obj_handlers;
395396

396397
return &obj->zo;

test/CreateTest.php

+10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
<?php
22

3+
4+
class TarantoolExt extends Tarantool {
5+
public $property = 42;
6+
}
7+
38
class CreateTest extends PHPUnit_Framework_TestCase
49
{
510
protected static $port, $tm;
@@ -140,6 +145,11 @@ public function test_08_good_credentials_construct($username, $password = null)
140145
$this->assertTrue($c->ping());
141146
}
142147

148+
public function test_09_inheritance() {
149+
$c = new TarantoolExt('localhost', self::$port);
150+
$this->assertEquals(42, $c->property);
151+
}
152+
143153
public static function provideGoodCredentials()
144154
{
145155
return [

0 commit comments

Comments
 (0)