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.
 
 

42 lines
636 B

<?php
namespace MethodsForAttribute {
use \MethodsFor as ForType;
use \Type;
#[ForType(Type::String)]
class StringMethods
{
public static function surround(string $value, string $left, string $right): string
{
return $left . $value . $right;
}
}
class User
{
public string $name = 'TypePHP';
}
#[\MethodsFor(User::class)]
class UserMethods
{
public static function displayName(User $user): string
{
return $user->name;
}
}
}
namespace {
function main(): void
{
$name = 'TypePHP';
echo $name->surround('<', '>');
echo (new \MethodsForAttribute\User())->displayName();
}
}