diff --git a/phpunit/code/re-assign-this.php b/phpunit/code/re-assign-this.php new file mode 100644 index 00000000..bec6a611 --- /dev/null +++ b/phpunit/code/re-assign-this.php @@ -0,0 +1,15 @@ +Bar(); + echo "OK\n"; +} \ No newline at end of file diff --git a/phpunit/src/ClassTest.php b/phpunit/src/ClassTest.php new file mode 100644 index 00000000..de641eee --- /dev/null +++ b/phpunit/src/ClassTest.php @@ -0,0 +1,10 @@ +exec('Cannot re-assign $this', 're-assign-this.php'); + } + +} diff --git a/phpunit/src/FunctionTest.php b/phpunit/src/FunctionTest.php index c03ef514..b4bc779e 100644 --- a/phpunit/src/FunctionTest.php +++ b/phpunit/src/FunctionTest.php @@ -6,4 +6,5 @@ class FunctionTest extends \BaseTest { $this->exec('The return type of the function `test` cannot be a reference type', 'function-return-ref.php'); } + } diff --git a/src/Php/CompilerBase.php b/src/Php/CompilerBase.php index 859e36a0..760809cd 100644 --- a/src/Php/CompilerBase.php +++ b/src/Php/CompilerBase.php @@ -245,7 +245,7 @@ class CompilerBase extends \PhpAot\Core\Translator protected string $buildDir; protected int $debugLine = 0; protected CLImate $climate; - protected bool $defaultNativeType = false; + protected bool $defaultNativeType = true; protected bool $stubFile = false; protected bool $enableProfiler = false; protected bool $forTest = false; diff --git a/src/Php/FuncCallOptimizer.php b/src/Php/FuncCallOptimizer.php index 926dd2d5..8490e90e 100644 --- a/src/Php/FuncCallOptimizer.php +++ b/src/Php/FuncCallOptimizer.php @@ -85,6 +85,9 @@ trait FuncCallOptimizer if ($name === 'pow') { return 'php::math::pow(' . $getArg(0) . ', ' . $getArg(1) . ')'; } + if ($name === 'strlen') { + return 'php::fn::strlen(' . $getArg(0) . ')'; + } if ($name === 'ord') { return 'php::fn::ord(' . $getArg(0) . ')'; } diff --git a/tests/core/lang/bug21094.phpt b/tests/core/lang/bug21094.phpt new file mode 100644 index 00000000..dd901012 --- /dev/null +++ b/tests/core/lang/bug21094.phpt @@ -0,0 +1,17 @@ +--TEST-- +Bug #21094 (set_error_handler not accepting methods) +--FILE-- + +--EXPECTF-- +[1024] errstr: test, errfile: %s, errline: %d diff --git a/tests/core/lang/bug21961.phpt b/tests/core/lang/bug21961.phpt new file mode 100644 index 00000000..48bd00b1 --- /dev/null +++ b/tests/core/lang/bug21961.phpt @@ -0,0 +1,58 @@ +--TEST-- +Bug #21961 (get_parent_class() segfault) +--FILE-- +name = 'Mr. X'; + $this->bars = array(); + } + + function getdrunk($where) + { + $this->bars[] = new bar($where); + } + + function getName() + { + return $this->name; + } +} + +class bar extends man +{ + public $name; + + function __construct($w) + { + $this->name = $w; + } + + function getName() + { + return $this->name; + } + + function whosdrunk() + { + $who = get_parent_class($this); + if($who == NULL) + { + return 'nobody'; + } + return eval("return ".$who.'::getName();'); + } +} + +function main() { + $x = new man; + $x->getdrunk('The old Tavern'); + var_dump($x->bars[0]->whosdrunk()); +} +?> +--EXPECT-- +string(14) "The old Tavern" diff --git a/tests/core/lang/bug23624.phpt b/tests/core/lang/bug23624.phpt new file mode 100644 index 00000000..f8778fff --- /dev/null +++ b/tests/core/lang/bug23624.phpt @@ -0,0 +1,12 @@ +--TEST-- +Bug #23624 (foreach leaves current array key as null) +--FILE-- + $value); + var_dump(current($arr)); +?> +--EXPECT-- +string(3) "one" +string(3) "one" diff --git a/tests/core/lang/bug26869.phpt b/tests/core/lang/bug26869.phpt new file mode 100644 index 00000000..065cf1dd --- /dev/null +++ b/tests/core/lang/bug26869.phpt @@ -0,0 +1,15 @@ +--TEST-- +Bug #26869 (constant as the key of static array) +--FILE-- + 1); + var_dump($a); + var_dump(isset($a[A])); +?> +--EXPECT-- +array(1) { + [1]=> + int(1) +} +bool(true) diff --git a/tests/core/lang/bug30726.phpt b/tests/core/lang/bug30726.phpt new file mode 100644 index 00000000..79aeff7d --- /dev/null +++ b/tests/core/lang/bug30726.phpt @@ -0,0 +1,8 @@ +--TEST-- +Bug #30726 (-.1 like numbers are not being handled correctly) +--FILE-- + +--EXPECT-- +1