From 7939f28f373efcd0bae7162d67eebc1a3b85f35a Mon Sep 17 00:00:00 2001 From: tianfenghan Date: Sat, 13 Jun 2026 18:14:06 +0800 Subject: [PATCH] =?UTF-8?q?test(phpunit):=20=E6=B7=BB=E5=8A=A0=E6=8A=BD?= =?UTF-8?q?=E8=B1=A1=E7=B1=BB=E5=92=8C=E7=A7=81=E6=9C=89=E6=96=B9=E6=B3=95?= =?UTF-8?q?=E9=87=8D=E5=86=99=E7=9A=84=E6=B5=8B=E8=AF=95=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 添加 testNewAbstractClass 方法测试抽象类实例化错误 - 添加 testOverridePrivateMethod 方法测试私有方法重写错误 - 使用 exec 方法验证预期的错误消息输出 - 扩展测试覆盖范围以包含更多边界情况 --- docs/UNSUPPORTED_SYNTAX.md | 117 ++++++++++++++++++++++++++++++++++++- phpunit/src/ClassTest.php | 10 ++++ 2 files changed, 125 insertions(+), 2 deletions(-) diff --git a/docs/UNSUPPORTED_SYNTAX.md b/docs/UNSUPPORTED_SYNTAX.md index 4de5df5e..85b7d1c5 100644 --- a/docs/UNSUPPORTED_SYNTAX.md +++ b/docs/UNSUPPORTED_SYNTAX.md @@ -2261,6 +2261,110 @@ function main() { --- +### 13. 类继承的编译期严格检查 + +**状态**: 行为差异 +**PHP 版本**: 所有版本 +**描述**: AOT 编译器在编译期对类继承关系进行比标准 PHP 更严格的检查。以下三种情况在标准 PHP 中是运行时错误,但在 AOT 中会在编译期直接报告致命错误。 + +#### 13.1 禁止实例化抽象类 + +在标准 PHP 中,`new AbstractClass()` 是运行时错误;AOT 在编译期检测到此类实例化时立即报错。 + +```php +exec('Cannot call abstract method `AbsBase::show()`', 'parent-abstract-method.php'); } + + public function testNewAbstractClass() + { + $this->exec('abstract class `AbstractBase` cannot be instantiated', 'abstract-class-new.php'); + } + + public function testOverridePrivateMethod() + { + $this->exec('Cannot override private method `Base::doWork()`', 'override-private-method.php'); + } }