diff --git a/kernels/ZendEngine3/object.c b/kernels/ZendEngine3/object.c index 62db7801a2..cf6a3d26ea 100644 --- a/kernels/ZendEngine3/object.c +++ b/kernels/ZendEngine3/object.c @@ -750,7 +750,9 @@ int zephir_update_property_array_append(zval *object, char *property, unsigned i zval new_zv; ZVAL_DUP(&new_zv, &tmp); ZVAL_COPY_VALUE(&tmp, &new_zv); - Z_TRY_DELREF(new_zv); + if (Z_REFCOUNT(tmp) > 1) { + Z_TRY_DELREF(new_zv); + } separated = 1; } } diff --git a/test/properties/propertyupdate.zep b/test/properties/propertyupdate.zep new file mode 100644 index 0000000000..3e09e4804f --- /dev/null +++ b/test/properties/propertyupdate.zep @@ -0,0 +1,10 @@ +namespace Test\Properties; + +class PropertyUpdate +{ + public p1; + + public function update1() { + let this->p1[] = "aaa"; + } +} diff --git a/unit-tests/Extension/Properties/PropertyUpdateTest.php b/unit-tests/Extension/Properties/PropertyUpdateTest.php new file mode 100644 index 0000000000..a8eb6b09c3 --- /dev/null +++ b/unit-tests/Extension/Properties/PropertyUpdateTest.php @@ -0,0 +1,28 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Extension\Properties; + +use PHPUnit\Framework\TestCase; +use Test\Properties\PropertyUpdate; + +class PropertyUpdateTest extends TestCase +{ + public function testUpdate11() + { + // before fixed. Assertion failed: (((ht)->gc.refcount == 1) || ((ht)->u.flags & (1<<6))), function _zend_hash_index_add_or_update_i + $t = new PropertyUpdate(); + $t->p1 = [111]; + $t->update1(); + + $this->assertSame($t->p1, [111, 'aaa']); + } +}