From dc338c7fed196cbc624dcdba6d606dfdc202e28b Mon Sep 17 00:00:00 2001 From: Yurun Date: Tue, 30 Jun 2026 20:30:55 +0800 Subject: [PATCH] =?UTF-8?q?fix(compiler):=20=E4=BF=AE=E5=A4=8D=E8=B7=A8?= =?UTF-8?q?=E5=91=BD=E5=90=8D=E7=A9=BA=E9=97=B4=20instanceof=20=E5=88=A4?= =?UTF-8?q?=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Php/CompilerBase.php | 3 +- tests/aot/namespace/interface-across-ns.phpt | 34 ++++++++++++++++++++ 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/src/Php/CompilerBase.php b/src/Php/CompilerBase.php index edf43899..31d12980 100644 --- a/src/Php/CompilerBase.php +++ b/src/Php/CompilerBase.php @@ -4342,8 +4342,7 @@ class CompilerBase extends \PhpAot\Core\Translator $this->assertExprCanBeUsedAsValue($expr->expr, 'instanceof operand'); if ($this->isNameExpr($expr->class)) { $className = $this->getNamespacedClassName($this->parseIdentifier($expr->class)); - $className = $this->getClassEntryPtr($className); - return 'php::instanceOf(' . $this->parseExpr($expr->expr) . ', ' . $className . ')'; + return 'php::instanceOf(' . $this->parseExpr($expr->expr) . ', ' . $this->getLiteralString($className) . ')'; } else { return 'php::instanceOf(' . $this->parseExpr($expr->expr) . ', ' . $this->identifierToStr($expr->class) . ')'; } diff --git a/tests/aot/namespace/interface-across-ns.phpt b/tests/aot/namespace/interface-across-ns.phpt index b6217a68..e3e96d98 100644 --- a/tests/aot/namespace/interface-across-ns.phpt +++ b/tests/aot/namespace/interface-across-ns.phpt @@ -29,6 +29,24 @@ namespace Services\Payment { return $this->log; } } + + class StripeProcessor2 implements \Contracts\Payment\PaymentProcessor { + private array $log = []; + + public function pay(float $amount): bool { + $this->log[] = "paid:{$amount}"; + return true; + } + + public function refund(float $amount): bool { + $this->log[] = "refunded:{$amount}"; + return true; + } + + public function getLog(): array { + return $this->log; + } + } } namespace { @@ -41,6 +59,13 @@ namespace { var_dump($p->refund(50.0)); var_dump($p->getLog()); var_dump($p instanceof PaymentProcessor); + + $p2 = new Services\Payment\StripeProcessor2(); + var_dump($p2->pay(200.0)); + var_dump($p2->refund(150.0)); + var_dump($p2->getLog()); + var_dump($p2 instanceof PaymentProcessor2); + echo "done\n"; } } @@ -55,4 +80,13 @@ array(2) { string(11) "refunded:50" } bool(true) +bool(true) +bool(true) +array(2) { + [0]=> + string(8) "paid:200" + [1]=> + string(12) "refunded:150" +} +bool(false) done -- 2.34.1