diff --git a/phpunit/src/TraitsTest.php b/phpunit/src/TraitsTest.php index 4bb014e5..af6a7f27 100644 --- a/phpunit/src/TraitsTest.php +++ b/phpunit/src/TraitsTest.php @@ -198,7 +198,10 @@ public function testGenPropertyPromotion(): void $argInfo->type = 'php::Str'; $result = $this->invoke('genPropertyPromotion', $argInfo); - $this->assertStringContainsString('this_.setProperty', $result); + $this->assertStringContainsString( + 'typephp_write_property_scoped(this_, "title", title, nullptr)', + $result, + ); $this->assertStringContainsString('title', $result); } diff --git a/src/Generator/PropertyPromotion.php b/src/Generator/PropertyPromotion.php index f59c1b99..3338c5bb 100644 --- a/src/Generator/PropertyPromotion.php +++ b/src/Generator/PropertyPromotion.php @@ -24,7 +24,11 @@ protected function genPropertyPromotion(ArgInfo $argInfo): string return 'this_.' . $this->getNativeObjectPropertyCppName($property, $this->classDef) . ' = ' . $value . ';' . PHP_EOL; } - $code .= 'this_.setProperty(' . $this->genCharPtr($propertyName) . ', ' . $argInfo->name . ')'; + $scope = $this->class !== '' + ? $this->getClassEntryPtr($this->getFullClassName()) + : 'nullptr'; + $code .= 'typephp_write_property_scoped(this_, ' + . $this->genCharPtr($propertyName) . ', ' . $argInfo->name . ', ' . $scope . ')'; $code .= ";\n"; return $code; } diff --git a/tests/compiler/object_ctor/promotion-inherited-private-scope.phpt b/tests/compiler/object_ctor/promotion-inherited-private-scope.phpt new file mode 100644 index 00000000..3dec531d --- /dev/null +++ b/tests/compiler/object_ctor/promotion-inherited-private-scope.phpt @@ -0,0 +1,29 @@ +--TEST-- +Constructor promotion writes inherited private promoted properties into the declared slot +--FILE-- + +--EXPECT-- +object(ChildCls)#1 (1) { + ["name":"ParentCls":private]=> + string(5) "hello" +} +object(ParentCls)#2 (1) { + ["name":"ParentCls":private]=> + string(6) "direct" +}