diff --git a/debug/ref.php b/debug/ref.php new file mode 100644 index 00000000..9463b731 --- /dev/null +++ b/debug/ref.php @@ -0,0 +1,60 @@ +assertFalse($classMethodOverride[$childMethodLower], 'ChildOverride::bar should not be marked as overridden'); } + + public function testNamespacedOverrideKeysUseFullClassName(): void + { + $compiler = CompilerTest::create(ROOT_PATH); + $testFile = __DIR__ . '/../code/class-method-override-namespace.php'; + $compiler->addFiles([$testFile]); + $compiler->prepareFile($testFile); + + $ref = new ReflectionClass($compiler); + $prop = $ref->getProperty('classMethodOverride'); + $classMethodOverride = $prop->getValue($compiler); + + $parentMethodLower = strtolower('Demo\\Dispatch\\ParentBaseNs::bar'); + $childMethodLower = strtolower('Demo\\Dispatch\\ChildOverrideNs::bar'); + + $this->assertArrayHasKey($parentMethodLower, $classMethodOverride, 'Namespaced parent method should be registered with full class name'); + $this->assertArrayHasKey($childMethodLower, $classMethodOverride, 'Namespaced child method should be registered with full class name'); + $this->assertTrue($classMethodOverride[$parentMethodLower], 'Namespaced parent method should be marked as overridden'); + $this->assertFalse($classMethodOverride[$childMethodLower], 'Namespaced child method should not be marked as overridden'); + } } diff --git a/tests/aot/dynamic_call/call-abstract-method.phpt b/tests/aot/dynamic_call/call-abstract-method.phpt index 266ab369..9596d1c2 100644 --- a/tests/aot/dynamic_call/call-abstract-method.phpt +++ b/tests/aot/dynamic_call/call-abstract-method.phpt @@ -2,8 +2,6 @@ call abstract base method through concrete object --FILE-- run(); +} + +function main(): int +{ + $r = invoke(new FastRunner()); + echo "result: $r\n"; + return $r === 'fast' ? 0 : 1; +} +?> +--EXPECT-- +result: fast diff --git a/tests/aot/dynamic_call/call-magic-fallback-typed-object.phpt b/tests/aot/dynamic_call/call-magic-fallback-typed-object.phpt new file mode 100644 index 00000000..515b2292 --- /dev/null +++ b/tests/aot/dynamic_call/call-magic-fallback-typed-object.phpt @@ -0,0 +1,29 @@ +--TEST-- +missing method on typed object dispatches to __call +--FILE-- +missing('a', 'b'); +} + +function main(): int +{ + $r = invoke(new DynamicHandler()); + echo "result: $r\n"; + return $r === 'missing:a,b' ? 0 : 1; +} +?> +--EXPECT-- +result: missing:a,b diff --git a/tests/aot/dynamic_call/call-multilevel-override.phpt b/tests/aot/dynamic_call/call-multilevel-override.phpt new file mode 100644 index 00000000..0cb7fda4 --- /dev/null +++ b/tests/aot/dynamic_call/call-multilevel-override.phpt @@ -0,0 +1,41 @@ +--TEST-- +call method overridden in grandchild through base parameter +--FILE-- +value(); +} + +function main(): int +{ + $r = readValue(new Leaf()); + echo "result: $r\n"; + return $r === 'leaf' ? 0 : 1; +} +?> +--EXPECT-- +result: leaf diff --git a/tests/aot/dynamic_call/call-namespaced-parent-override.phpt b/tests/aot/dynamic_call/call-namespaced-parent-override.phpt index 91318641..0bf1dacb 100644 --- a/tests/aot/dynamic_call/call-namespaced-parent-override.phpt +++ b/tests/aot/dynamic_call/call-namespaced-parent-override.phpt @@ -3,8 +3,6 @@ call overridden method through namespaced parent type --FILE-- name(); +} + +function main(): int +{ + $left = readName(new Left()); + $right = readName(new Right()); + echo "left: $left\n"; + echo "right: $right\n"; + return $left === 'left' && $right === 'right' ? 0 : 1; +} +?> +--EXPECT-- +left: left +right: right diff --git a/tests/aot/dynamic_call/call-protected-override.phpt b/tests/aot/dynamic_call/call-protected-override.phpt new file mode 100644 index 00000000..2f794f4a --- /dev/null +++ b/tests/aot/dynamic_call/call-protected-override.phpt @@ -0,0 +1,41 @@ +--TEST-- +protected overridden method remains virtual through parent wrapper +--FILE-- +token(); + } +} + +class Child extends Base +{ + protected function token(): string + { + return 'child'; + } +} + +function main(): int +{ + $base = new Base(); + $child = new Child(); + $a = $base->expose(); + $b = $child->expose(); + echo "base: $a\n"; + echo "child: $b\n"; + return $a === 'base' && $b === 'child' ? 0 : 1; +} +?> +--EXPECT-- +base: base +child: child