parent
223a10636b
commit
9ad213ea64
7 changed files with 136 additions and 1 deletions
@ -0,0 +1,21 @@ |
|||||||
|
<?php |
||||||
|
/** |
||||||
|
* This file is part of TypePHP(AOT). |
||||||
|
* |
||||||
|
* @link https://www.swoole.com/aot/ |
||||||
|
* @contact service@swoole.com |
||||||
|
*/ |
||||||
|
|
||||||
|
function main(): void |
||||||
|
{ |
||||||
|
$args = [[1, 2, 3]]; |
||||||
|
var_dump(count(...$args)); |
||||||
|
var_dump(count(...[[1, 2, 3]])); |
||||||
|
|
||||||
|
try { |
||||||
|
var_dump(count(...[])); |
||||||
|
echo "argument-count-error-not-thrown\n"; |
||||||
|
} catch (ArgumentCountError $error) { |
||||||
|
echo "caught=", $error->getMessage(), "\n"; |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,22 @@ |
|||||||
|
<?php |
||||||
|
/** |
||||||
|
* This file is part of TypePHP(AOT). |
||||||
|
* |
||||||
|
* @link https://www.swoole.com/aot/ |
||||||
|
* @contact service@swoole.com |
||||||
|
*/ |
||||||
|
|
||||||
|
function main(): void |
||||||
|
{ |
||||||
|
$intvalArgs = ['ff', 16]; |
||||||
|
$roundArgs = [2.5, 0, PHP_ROUND_HALF_DOWN]; |
||||||
|
$nullArgs = [null]; |
||||||
|
$arrayKeysArgs = [['a' => 1]]; |
||||||
|
$functionExistsArgs = ['strlen']; |
||||||
|
|
||||||
|
var_dump(intval(...$intvalArgs)); |
||||||
|
var_dump(round(...$roundArgs)); |
||||||
|
var_dump(is_null(...$nullArgs)); |
||||||
|
var_dump(array_keys(...$arrayKeysArgs)); |
||||||
|
var_dump(function_exists(...$functionExistsArgs)); |
||||||
|
} |
||||||
@ -0,0 +1,36 @@ |
|||||||
|
<?php |
||||||
|
/** |
||||||
|
* This file is part of TypePHP(AOT). |
||||||
|
* |
||||||
|
* @link https://www.swoole.com/aot/ |
||||||
|
* @contact service@swoole.com |
||||||
|
*/ |
||||||
|
|
||||||
|
namespace TypePhp\Tests; |
||||||
|
|
||||||
|
use PHPUnit\Framework\TestCase; |
||||||
|
use TypePhp\CompilerTest; |
||||||
|
|
||||||
|
/** |
||||||
|
* @internal |
||||||
|
* @coversNothing |
||||||
|
*/ |
||||||
|
class FuncCallOptimizerUnpackTest extends TestCase |
||||||
|
{ |
||||||
|
public function testOptimizedFunctionsLeaveArgumentUnpackingToTheRuntime(): void |
||||||
|
{ |
||||||
|
global $translator; |
||||||
|
|
||||||
|
$compiler = CompilerTest::create(TYPEPHP_ROOT_PATH); |
||||||
|
$translator = $compiler; |
||||||
|
$source = TYPEPHP_ROOT_PATH . '/phpunit/code/func-call-optimizer-unpack.php'; |
||||||
|
$compiler->addFiles([$source]); |
||||||
|
$compiler->prepareFile($source); |
||||||
|
$cpp = file_get_contents($compiler->convertFile($source)); |
||||||
|
|
||||||
|
self::assertSame(5, substr_count($cpp, '.appendUnpacked(')); |
||||||
|
self::assertStringNotContainsString('php::toInt(', $cpp); |
||||||
|
self::assertStringNotContainsString('php::fn::round(', $cpp); |
||||||
|
self::assertStringNotContainsString('php::fn::array_keys(', $cpp); |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,28 @@ |
|||||||
|
--TEST-- |
||||||
|
optimized builtin calls preserve argument unpacking |
||||||
|
--FILE-- |
||||||
|
<?php |
||||||
|
function main(): void |
||||||
|
{ |
||||||
|
$intvalArgs = ['ff', 16]; |
||||||
|
$roundArgs = [2.5, 0, PHP_ROUND_HALF_DOWN]; |
||||||
|
$nullArgs = [null]; |
||||||
|
$arrayKeysArgs = [['a' => 1]]; |
||||||
|
$functionExistsArgs = ['strlen']; |
||||||
|
|
||||||
|
var_dump(intval(...$intvalArgs)); |
||||||
|
var_dump(round(...$roundArgs)); |
||||||
|
var_dump(is_null(...$nullArgs)); |
||||||
|
var_dump(array_keys(...$arrayKeysArgs)); |
||||||
|
var_dump(function_exists(...$functionExistsArgs)); |
||||||
|
} |
||||||
|
?> |
||||||
|
--EXPECT-- |
||||||
|
int(255) |
||||||
|
float(2) |
||||||
|
bool(true) |
||||||
|
array(1) { |
||||||
|
[0]=> |
||||||
|
string(1) "a" |
||||||
|
} |
||||||
|
bool(true) |
||||||
Loading…
Reference in new issue