Skip to content

Commit

Permalink
Properly initialize Tarantool instance properties
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Totktonada committed Mar 28, 2020
1 parent 176d49f commit 905a70f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/tarantool.c
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,7 @@ static zend_object *tarantool_create(zend_class_entry *entry) {
obj = (tarantool_object *)pecalloc(1, sizeof(tarantool_object) +
sizeof(zval) * (entry->default_properties_count - 1), 0);
zend_object_std_init(&obj->zo, entry);
object_properties_init(&obj->zo, entry);
obj->zo.handlers = &tarantool_obj_handlers;

return &obj->zo;
Expand Down
7 changes: 7 additions & 0 deletions test/CreateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,13 @@ public function test_08_good_credentials_construct($username, $password = null)
$this->assertTrue($c->ping());
}

public function test_09_inheritance() {
$c = new class ('localhost', self::$port) extends Tarantool {
public $property = 42;
};
$this->assertSame(42, $c->property);
}

public static function provideGoodCredentials()
{
return [
Expand Down

0 comments on commit 905a70f

Please sign in to comment.