Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion phpunit/src/TraitsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
6 changes: 5 additions & 1 deletion src/Generator/PropertyPromotion.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
29 changes: 29 additions & 0 deletions tests/compiler/object_ctor/promotion-inherited-private-scope.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
--TEST--
Constructor promotion writes inherited private promoted properties into the declared slot
--FILE--
<?php
class ParentCls
{
public function __construct(private string $name = "default") {}
}

class ChildCls extends ParentCls {}

function main(): void
{
$child = new ChildCls("hello");
var_dump($child);

$direct = new ParentCls("direct");
var_dump($direct);
}
?>
--EXPECT--
object(ChildCls)#1 (1) {
["name":"ParentCls":private]=>
string(5) "hello"
}
object(ParentCls)#2 (1) {
["name":"ParentCls":private]=>
string(6) "direct"
}
Loading