diff --git a/examples/micro_bench.php b/examples/micro_bench.php index 27c9af67..325b6a1b 100644 --- a/examples/micro_bench.php +++ b/examples/micro_bench.php @@ -23,7 +23,7 @@ function simpleicall($n) } class Foo { - static $a = 0; + static $a = 12; public $b = 0; const TEST = 23; diff --git a/src/Php/CompilerBase.php b/src/Php/CompilerBase.php index 760809cd..6313b5f3 100644 --- a/src/Php/CompilerBase.php +++ b/src/Php/CompilerBase.php @@ -3648,15 +3648,20 @@ class CompilerBase extends \PhpAot\Core\Translator protected function parseChainedExpr(NodeAbstract $node, string $op, bool $getValue = false): string { + // AOT 编译器不允许操作未定义的变量,PHP 的 isset($var) 可能 $var 未定义 + $this->checkVarMustExist($node, $this->parseIdentifier($node)); $fn = $this->getChainedFunc($op); $expr = $node; if ($this->isVarExpr($expr)) { - if ($op === self::OP_ISSET) { - $var = $this->parseIdentifier($expr); - return $this->hasVar($var) ? $fn . '(' . $var . ')' : 'false'; - } return $fn . '(' . $this->parseExpr($expr) . ')'; } + // 单属性读取(非链式) + if ($this->isPropertyFetch($expr) and $this->isVarExpr($expr->var) and $this->isIdExpr($expr->name)) { + $prop = $this->parsePropertyFetch($expr); + if ($expr->hasAttribute('nativeProperty')) { + return $fn . '(' . $prop . ')'; + } + } $list = []; while (true) { @@ -3681,8 +3686,6 @@ class CompilerBase extends \PhpAot\Core\Translator $expr = $expr->var; } - $list = array_reverse($list); - if ($getValue) { $result = $this->addTmpVar(self::TYPE_VAR); $node->setAttribute('chainOpResult', $result); diff --git a/src/template/extension.cc.php b/src/template/extension.cc.php index d48b5707..6370ef00 100644 --- a/src/template/extension.cc.php +++ b/src/template/extension.cc.php @@ -58,9 +58,9 @@ zend_function *php_get_method(int func_id, const php::Str &method_name, int clas uint32_t php_get_prop(int prop_id, const php::Str &prop_name, int class_id, const php::Str &class_name) { if (UNEXPECTED([prop_id] == 0)) { - [prop_id] = php::getPropertyOffset(class_name, prop_name); + [prop_id] = php::getPropertyOffset(class_name, prop_name) + 1024; } - return [prop_id]; + return [prop_id] - 1024; } // literal strings