From 4b22f649766ab2bbd6a81a6c817442e4b3cd1743 Mon Sep 17 00:00:00 2001 From: yavon007 Date: Sat, 5 Sep 2026 11:56:15 +0800 Subject: [PATCH] fix dynamic static calls on object targets --- phpunit/code/call-cache-sites.php | 7 ++++ phpunit/src/CallCacheCodegenTest.php | 4 +-- src/Parser/MethodCallTrait.php | 5 ++- .../static-call-dynamic-object-method.phpt | 34 +++++++++++++++++++ 4 files changed, 47 insertions(+), 3 deletions(-) create mode 100644 tests/compiler/static/static-call-dynamic-object-method.phpt diff --git a/phpunit/code/call-cache-sites.php b/phpunit/code/call-cache-sites.php index 8a3f0f64..71ee3e9b 100644 --- a/phpunit/code/call-cache-sites.php +++ b/phpunit/code/call-cache-sites.php @@ -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 diff --git a/phpunit/src/CallCacheCodegenTest.php b/phpunit/src/CallCacheCodegenTest.php index ee5f953b..2058c34a 100644 --- a/phpunit/src/CallCacheCodegenTest.php +++ b/phpunit/src/CallCacheCodegenTest.php @@ -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::arrayisNameExpr($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; } diff --git a/tests/compiler/static/static-call-dynamic-object-method.phpt b/tests/compiler/static/static-call-dynamic-object-method.phpt new file mode 100644 index 00000000..8b6d0a34 --- /dev/null +++ b/tests/compiler/static/static-call-dynamic-object-method.phpt @@ -0,0 +1,34 @@ +--TEST-- +Dynamic static method name on object target uses the runtime method value +--FILE-- + +--EXPECT-- +string(10) "base:first" +string(12) "child:second"