diff --git a/examples/autoload_class.php b/examples/autoload_class.php index c5585be2..cddcc72f 100644 --- a/examples/autoload_class.php +++ b/examples/autoload_class.php @@ -11,3 +11,5 @@ function main() $o = new CpuCoreCounter(); var_dump($o->getCount()); } + +test(); \ No newline at end of file diff --git a/src/Php/CompilerBase.php b/src/Php/CompilerBase.php index 7884f069..8ef6cf45 100644 --- a/src/Php/CompilerBase.php +++ b/src/Php/CompilerBase.php @@ -1799,6 +1799,11 @@ class CompilerBase extends \PhpAot\Core\Translator return false; } + protected function foundStrayCode(): never + { + $this->error("All execution code must be within a function; there is no allowance for stray code."); + } + protected function parseFuncCall(Node\Expr\FuncCall $expr, bool $silent = false): string { $call = ''; diff --git a/src/Php/Preprocessor.php b/src/Php/Preprocessor.php index a5172481..29428ef6 100644 --- a/src/Php/Preprocessor.php +++ b/src/Php/Preprocessor.php @@ -105,9 +105,10 @@ class Preprocessor extends CompilerBase case 'Stmt_Const': $this->parseConstDef($v); break; + case 'Stmt_Expression': + $this->foundStrayCode(); default: $this->fatalError($v, 'Unsupported statement: ' . $type); - break; } } @@ -142,6 +143,8 @@ class Preprocessor extends CompilerBase case 'Stmt_Use': case 'Stmt_Const': break; + case 'Stmt_Expression': + $this->foundStrayCode(); default: abort($v2); } @@ -174,6 +177,8 @@ class Preprocessor extends CompilerBase case 'Stmt_ClassMethod': $code .= $this->prepareFunction($v) . PHP_EOL; break; + case 'Stmt_Expression': + $this->foundStrayCode(); default: abort($v); } diff --git a/src/template/extension.cc.php b/src/template/extension.cc.php index 606973a6..90b6b650 100644 --- a/src/template/extension.cc.php +++ b/src/template/extension.cc.php @@ -72,6 +72,9 @@ endforeach; static const zend_function_entry ext_functions[] = { functions as $functionDef): + if ($this->buildMode === 'ext' and $functionDef->name === 'main') { + continue; + } ?> ZEND_FE(name?>, arginfo_name?>) diff --git a/tests/aot/empty-2.phpt b/tests/aot/empty-2.phpt new file mode 100644 index 00000000..a8e5f2df --- /dev/null +++ b/tests/aot/empty-2.phpt @@ -0,0 +1,15 @@ +--TEST-- +empty 2 +--FILE-- + +--EXPECT-- +int(1) +int(3)