TypePHP 编译器
https://swoole.com/aot/
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
38 lines
595 B
38 lines
595 B
--TEST--
|
|
Universal method: extension functions
|
|
--FILE--
|
|
<?php
|
|
|
|
use native_types;
|
|
|
|
function int_to_bytes(int $int, string $unit = 'Kb'): string
|
|
{
|
|
return ($int / 1024) . $unit;
|
|
}
|
|
|
|
function array_get_first_element(array $array): mixed
|
|
{
|
|
return $array[0];
|
|
}
|
|
|
|
function str_shout(string $str): string
|
|
{
|
|
return strtoupper($str) . '!';
|
|
}
|
|
|
|
function main()
|
|
{
|
|
$num = 1024 * 512;
|
|
var_dump($num->toBytes());
|
|
|
|
$array = [22, 33, 44];
|
|
var_dump($array->getFirstElement());
|
|
|
|
$str = "hello";
|
|
var_dump($str->shout());
|
|
}
|
|
?>
|
|
--EXPECT--
|
|
string(5) "512Kb"
|
|
int(22)
|
|
string(6) "HELLO!"
|
|
|