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.
36 lines
602 B
36 lines
602 B
--TEST--
|
|
Universal MethodsFor methods use their declared names
|
|
--FILE--
|
|
<?php
|
|
|
|
use native_types;
|
|
|
|
#[MethodsFor(Type::Int)]
|
|
final class IntExtensions
|
|
{
|
|
public static function toBytes(int $value): string
|
|
{
|
|
return ($value / 1024) . 'Kb';
|
|
}
|
|
}
|
|
|
|
#[MethodsFor(Type::Array)]
|
|
final class ArrayExtensions
|
|
{
|
|
public static function getFirstElement(array $value): mixed
|
|
{
|
|
return $value[0];
|
|
}
|
|
}
|
|
|
|
function main(): void
|
|
{
|
|
$size = 2048;
|
|
$values = [42, 43];
|
|
var_dump($size->toBytes());
|
|
var_dump($values->getFirstElement());
|
|
}
|
|
?>
|
|
--EXPECT--
|
|
string(3) "2Kb"
|
|
int(42)
|
|
|