diff --git a/src/Php/CompilerBase.php b/src/Php/CompilerBase.php index cf687443..36ab3cbe 100644 --- a/src/Php/CompilerBase.php +++ b/src/Php/CompilerBase.php @@ -3360,10 +3360,10 @@ class CompilerBase extends \PhpAot\Core\Translator return $id; } if ($id === 'self') { - $id = $this->class; + $id = $this->classDef->getNamespacedName(false); } if ($this->isNameExpr($node) or $this->isIdExpr($node)) { - return $this->genCharPtr($id); + return $this->genCharPtr($id, true); } return $id; } diff --git a/src/Php/Translator.php b/src/Php/Translator.php index 6532c282..3eaf752f 100644 --- a/src/Php/Translator.php +++ b/src/Php/Translator.php @@ -32,6 +32,7 @@ class Translator extends Preprocessor protected array $phpSrcFiles = []; protected array $argInfoHeaderFiles = []; protected array $registerSymbols = []; + protected array $staticPropertyList = []; protected bool $useRegisterSymbolsFn = false; protected array $unsupportedFunctions = [ 'compact', @@ -811,8 +812,16 @@ class Translator extends Preprocessor foreach ($classDef->properties as $property) { if ($property->type === self::TYPE_ARRAY and $property->default and $property->default !== self::TYPE_ARRAY . '{}') { - $propOffset = self::PREFIX . $this->getPropertyOffset($property->name, $classDef->name, $classDef->namespace); - $cppCode .= $this->getIndent() . 'this_.attr(' . $propOffset . ') = ' . $property->default . ';' . PHP_EOL; + if ($property->isStatic()) { + $prop = new \stdClass(); + $prop->class = $classDef->getNamespacedName(false); + $prop->name = $property->name; + $prop->default = $property->default; + $this->staticPropertyList[] = $prop; + } else { + $propOffset = self::PREFIX . $this->getPropertyOffset($property->name, $classDef->name, $classDef->namespace); + $cppCode .= $this->getIndent() . 'this_.attr(' . $propOffset . ') = ' . $property->default . ';' . PHP_EOL; + } } } @@ -940,11 +949,14 @@ class Translator extends Preprocessor $flags |= Modifiers::PUBLIC; } - $this->methodDef = new MethodDef($flags, $name); - $methodCodes[$name] = $this->parseFunction($v); + if (!($flags & Modifiers::ABSTRACT)) { + $this->methodDef = new MethodDef($flags, $name); + $methodCodes[$name] = $this->parseFunction($v); + + $this->checkRequiredArgNum($name, $this->methodDef, $v); + $this->classDef->methods[$name] = $this->methodDef; + } - $this->checkRequiredArgNum($name, $this->methodDef, $v); - $this->classDef->methods[$name] = $this->methodDef; $this->resetMethod(); } diff --git a/src/template/extension.cc.php b/src/template/extension.cc.php index c761cc8f..31e80101 100644 --- a/src/template/extension.cc.php +++ b/src/template/extension.cc.php @@ -139,6 +139,14 @@ foreach ($this->classes as $classDef): + // static property +staticPropertyList as $prop): +?> + php::setStaticProperty(genCharPtr($prop->class, true)?>, genCharPtr($prop->name)?>, default?>); + } diff --git a/tests/aot/bool-001.phpt b/tests/aot/bool-001.phpt new file mode 100644 index 00000000..d5ce9574 --- /dev/null +++ b/tests/aot/bool-001.phpt @@ -0,0 +1,13 @@ +--TEST-- +bool 001 +--FILE-- + 0 && $offset); +} +?> +--EXPECT-- +bool(true) \ No newline at end of file diff --git a/tests/aot/ctor.phpt b/tests/aot/ctor.phpt new file mode 100644 index 00000000..24c0e788 --- /dev/null +++ b/tests/aot/ctor.phpt @@ -0,0 +1,39 @@ +--TEST-- +ctor +--FILE-- + 0, + 'worker_exit_info' => [] + ]; + public ?string $workerId = null; + public function __construct(?string $socketName = null) + { + $this->workerId = spl_object_hash($this); + var_dump($socketName); + var_dump(self::$globalStatistics); + } + } +} +namespace { + function main() + { + $obj = new \Test\Worker("hello"); + var_dump($obj->workerId); + } +} +?> +--EXPECT-- +string(5) "hello" +array(2) { + ["start_timestamp"]=> + int(0) + ["worker_exit_info"]=> + array(0) { + } +} +string(32) "00000000000000010000000000000000" \ No newline at end of file