From 0e319c48de72125600493302d53b5085128059fb Mon Sep 17 00:00:00 2001 From: tianfenghan Date: Thu, 23 Apr 2026 13:31:18 +0800 Subject: [PATCH] =?UTF-8?q?fix(php):=20=E4=BF=AE=E5=A4=8D=E5=8E=9F?= =?UTF-8?q?=E7=94=9F=E7=B1=BB=E5=9E=8B=E5=8F=98=E9=87=8F=E5=92=8C=E5=AF=B9?= =?UTF-8?q?=E8=B1=A1=E5=B1=9E=E6=80=A7=E7=9A=84=20unset=20=E6=93=8D?= =?UTF-8?q?=E4=BD=9C=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修改对象属性 unset 警告消息为更准确的描述 - 添加对原生类型变量的 unset 操作检查和警告 - 阻止原生类型变量执行 unset 操作 - 新增 unset 原生类型变量的测试用例 - 完善变量类型检查逻辑以区分原生类型 --- examples/error/unset-int-var.php | 9 +++++++++ src/Php/CompilerBase.php | 9 +++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 examples/error/unset-int-var.php diff --git a/examples/error/unset-int-var.php b/examples/error/unset-int-var.php new file mode 100644 index 00000000..3c68ff2b --- /dev/null +++ b/examples/error/unset-int-var.php @@ -0,0 +1,9 @@ +isIdExpr($var->name)) { $propName = $this->parseIdentifier($var->name); if ($this->hasObjectPropVar($this->getObjectPropVarName($object, $propName))) { - $this->warning($var, "Unset of object property `{$propName}` is not allowed"); + $this->warning($var, "Object property `$propName` of native types cannot be unset"); $lines = []; $lines[] = $this->getObjectPropVarName($object, $propName) . " = 0;"; } @@ -3442,7 +3442,12 @@ class CompilerBase extends \PhpAot\Core\Translator if (!$this->hasVar($name)) { $this->errorUndefinedVariable($var); } - $lines[] = "{$name}.unset();"; + $type = $this->getVarType($name); + if ($this->isNativeType($type)) { + $this->warning($var, "Variable of native type `\${$name}` cannot be unset"); + } else { + $lines[] = "{$name}.unset();"; + } } else { $this->fatalError($var, "Unsupported unset type `{$var->getType()}`"); }