fix(compiler): 修复跨命名空间 instanceof 判断

pull/5/head
Yurun 2 months ago
parent 87c54236a0
commit dc338c7fed
  1. 3
      src/Php/CompilerBase.php
  2. 34
      tests/aot/namespace/interface-across-ns.phpt

@ -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) . ')';
}

@ -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

Loading…
Cancel
Save