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
7 changes: 7 additions & 0 deletions phpunit/code/call-cache-sites.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -38,6 +38,13 @@ function call_cache_static_sites(mixed $class, mixed $method): array
];
}

function call_cache_stable_object_static_method(mixed $method): int
{
$object = new CallCacheStaticTarget();

return $object::$method(8);
}

class CallCacheScopedTarget
{
private function hidden(): int
Expand Down
4 changes: 2 additions & 2 deletions phpunit/src/CallCacheCodegenTest.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -26,9 +26,9 @@ public function testDynamicCallSitesUseRequestLocalTypePhpCaches(): void
self::assertIsString($code);
self::assertIsString($extension);
self::assertSame(1, substr_count($code, 'typephp_call_cached('));
self::assertSame(3, substr_count($code, 'php::callStaticMethod('));
self::assertSame(4, substr_count($code, 'php::callStaticMethod('));
self::assertStringNotContainsString('php::concat({', $code);
self::assertSame(8, substr_count($code, 'php::VarList{'));
self::assertSame(9, substr_count($code, 'php::VarList{'));
self::assertStringNotContainsString('std::array<php::Variant', $code);
self::assertStringNotContainsString('php::ArgList{', $code);
self::assertSame(2, substr_count($code, 'typephp_call_method_cached('));
Expand Down
5 changes: 4 additions & 1 deletion src/Parser/MethodCallTrait.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -1099,7 +1099,10 @@ protected function parseStaticCall(Expr\StaticCall $expr): string
}

if (!$this->isNameExpr($expr->class)) {
if ($this->isVarExpr($expr->class) && $this->isStableObject($class)) {
if ($this->isVarExpr($expr->class)
&& $this->isStableObject($class)
&& $this->isIdExpr($expr->name)
) {
$class = $this->getObjectType($class);
goto _do_call;
}
Expand Down
34 changes: 34 additions & 0 deletions tests/compiler/static/static-call-dynamic-object-method.phpt
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
--TEST--
Dynamic static method name on object target uses the runtime method value
--FILE--
<?php

class DynamicObjectStaticTarget
{
public static function reward(string $value): string
{
return 'base:' . $value;
}
}

class DynamicObjectStaticChild extends DynamicObjectStaticTarget
{
public static function reward(string $value): string
{
return 'child:' . $value;
}
}

function main(): void
{
$method = 'reward';
$target = new DynamicObjectStaticTarget();
$child = new DynamicObjectStaticChild();

var_dump($target::$method('first'));
var_dump($child::$method(value: 'second'));
}
?>
--EXPECT--
string(10) "base:first"
string(12) "child:second"