diff --git a/src/Php/CompilerBase.php b/src/Php/CompilerBase.php index 36e53958..6f5483d6 100644 --- a/src/Php/CompilerBase.php +++ b/src/Php/CompilerBase.php @@ -1515,7 +1515,7 @@ class CompilerBase extends \PhpAot\Core\Translator if (count($expr->args) === 2 and $fn === 'objval') { $argClass = $expr->args[1]->value; if ($this->isScalarString($argClass)) { - return $this->getNamespacedClassName($this->parseIdentifier($argClass)); + return $this->getNamespacedClassName($argClass->value); } if ($this->isClassConstFetch($argClass)) { if ($this->isNameExpr($argClass->class) and $this->isIdExpr($argClass->name) and $this->parseIdentifier($argClass->name) === 'class') { @@ -4325,7 +4325,7 @@ class CompilerBase extends \PhpAot\Core\Translator $class = $this->getNamespacedClassName($class); if ($const === 'class') { - return '"' . $this->escapeString($class) . '"'; + return $this->getLiteralString($class); } if (($self or $this->isNameExpr($expr->class)) and $this->isIdExpr($expr->name)) { if ($this->hasClass($class)) { diff --git a/src/Php/Constants.php b/src/Php/Constants.php index 4a83d0ab..3c1706ae 100644 --- a/src/Php/Constants.php +++ b/src/Php/Constants.php @@ -62,7 +62,79 @@ class Constants 'this_', // phpx keywords ]; - public const UNSUPPORTED_FUNCTIONS = [ + public const array UNSUPPORTED_FUNCTIONS = [ 'extract', ]; + + public const array COMPILER_OPTIONS = [ + 'optimize' => [ + 'prefix' => 'O', + 'longPrefix' => 'optimize', + 'description' => 'Set the optimization level of the gcc compiler to 0 by default', + 'required' => false, + 'castTo' => 'int', + 'defaultValue' => 0, + ], + 'output' => [ + 'prefix' => 'o', + 'longPrefix' => 'output', + 'description' => 'Output file', + ], + 'help' => [ + 'prefix' => 'h', + 'longPrefix' => 'help', + 'description' => 'Show help', + 'noValue' => true, + ], + 'version' => [ + 'prefix' => 'v', + 'longPrefix' => 'version', + 'description' => 'Show Version', + 'noValue' => true, + ], + 'profile' => [ + 'longPrefix' => 'profile', + 'description' => 'Enable performance profiling', + 'required' => false, + 'noValue' => true, + ], + 'noLiteralStrings' => [ + 'longPrefix' => 'no-literal-strings', + 'description' => 'Disable literal strings optimization', + 'required' => false, + 'noValue' => true, + ], + 'force' => [ + 'prefix' => 'f', + 'longPrefix' => 'force', + 'description' => 'Force compile even if cache exists', + 'required' => false, + 'noValue' => true, + ], + 'mode' => [ + 'longPrefix' => 'mode', + 'prefix' => 'm', + 'description' => 'Build mode, -m bin(binary) or -m ext(extension), default: bin', + 'required' => false, + 'defaultValue' => 'bin', + ], + 'debug-line' => [ + 'longPrefix' => 'debug-line', + 'description' => 'Enable debug line', + 'required' => false, + 'defaultValue' => 0, + ], + 'debug-info' => [ + 'longPrefix' => 'debug-info', + 'description' => 'Enable debug info', + 'required' => false, + ], + 'job' => [ + 'prefix' => 'j', + 'longPrefix' => 'job', + 'description' => 'Number of jobs to run in parallel', + 'required' => false, + 'defaultValue' => 4, + ], + ]; } diff --git a/src/Php/Translator.php b/src/Php/Translator.php index d78c16c0..ce9377e9 100644 --- a/src/Php/Translator.php +++ b/src/Php/Translator.php @@ -49,7 +49,7 @@ class Translator extends Preprocessor public function __construct(string $rootPath) { parent::__construct($rootPath); - $this->climate->arguments->add(require __DIR__ . '/../config/compiler_options.php'); + $this->climate->arguments->add(Constants::COMPILER_OPTIONS); $this->preprocessArgvAdvanced(); $this->climate->arguments->parse(); diff --git a/src/config/compiler_options.php b/src/config/compiler_options.php deleted file mode 100644 index 94f62ea8..00000000 --- a/src/config/compiler_options.php +++ /dev/null @@ -1,72 +0,0 @@ - [ - 'prefix' => 'O', - 'longPrefix' => 'optimize', - 'description' => 'Set the optimization level of the gcc compiler to 0 by default', - 'required' => false, - 'castTo' => 'int', - 'defaultValue' => 0, - ], - 'output' => [ - 'prefix' => 'o', - 'longPrefix' => 'output', - 'description' => 'Output file', - ], - 'help' => [ - 'prefix' => 'h', - 'longPrefix' => 'help', - 'description' => 'Show help', - 'noValue' => true, - ], - 'version' => [ - 'prefix' => 'v', - 'longPrefix' => 'version', - 'description' => 'Show Version', - 'noValue' => true, - ], - 'profile' => [ - 'longPrefix' => 'profile', - 'description' => 'Enable performance profiling', - 'required' => false, - 'noValue' => true, - ], - 'noLiteralStrings' => [ - 'longPrefix' => 'no-literal-strings', - 'description' => 'Disable literal strings optimization', - 'required' => false, - 'noValue' => true, - ], - 'force' => [ - 'prefix' => 'f', - 'longPrefix' => 'force', - 'description' => 'Force compile even if cache exists', - 'required' => false, - 'noValue' => true, - ], - 'mode' => [ - 'longPrefix' => 'mode', - 'prefix' => 'm', - 'description' => 'Build mode, -m bin(binary) or -m ext(extension), default: bin', - 'required' => false, - 'defaultValue' => 'bin', - ], - 'debug-line' => [ - 'longPrefix' => 'debug-line', - 'description' => 'Enable debug line', - 'required' => false, - 'defaultValue' => 0, - ], - 'debug-info' => [ - 'longPrefix' => 'debug-info', - 'description' => 'Enable debug info', - 'required' => false, - ], - 'job' => [ - 'prefix' => 'j', - 'longPrefix' => 'job', - 'description' => 'Number of jobs to run in parallel', - 'required' => false, - 'defaultValue' => 4, - ], -]; \ No newline at end of file diff --git a/tests/aot/objval.phpt b/tests/aot/objval.phpt new file mode 100644 index 00000000..9e4ddd8f --- /dev/null +++ b/tests/aot/objval.phpt @@ -0,0 +1,37 @@ +--TEST-- +objval +--FILE-- +a = $a; + $this->b = $b; + } + + public function test() + { + return $this->a + $this->b; + } +} + +function main() +{ + $obj = new TestObjval(1, 2); + $arr = array(); + $arr['obj'] = $obj; + $obj2 = objval($arr['obj'], 'TestObjval'); + var_dump($obj2->test()); + + $obj3 = objval($obj, TestObjval::class); + var_dump($obj3->test()); +} +?> +--EXPECT-- +int(3) +int(3) \ No newline at end of file