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.
63 lines
1000 B
63 lines
1000 B
<?php
|
|
|
|
class BaseAnimal
|
|
{
|
|
public static function identify(): string
|
|
{
|
|
return 'base';
|
|
}
|
|
}
|
|
|
|
class DogAnimal extends BaseAnimal
|
|
{
|
|
public static function identify(): string
|
|
{
|
|
return 'dog';
|
|
}
|
|
}
|
|
|
|
function makeAnimal(): BaseAnimal
|
|
{
|
|
return new DogAnimal();
|
|
}
|
|
|
|
function getExactClass(): string
|
|
{
|
|
$dog = new DogAnimal();
|
|
return get_class($dog);
|
|
}
|
|
|
|
function getPolymorphicClass(): string
|
|
{
|
|
$animal = makeAnimal();
|
|
return get_class($animal);
|
|
}
|
|
|
|
function callExactStatic(): string
|
|
{
|
|
$dog = new DogAnimal();
|
|
return $dog::identify();
|
|
}
|
|
|
|
function callPolymorphicStatic(): string
|
|
{
|
|
$animal = makeAnimal();
|
|
return $animal::identify();
|
|
}
|
|
|
|
class BaseScopedCaller
|
|
{
|
|
protected static function identifyProtected(): string
|
|
{
|
|
return static::class;
|
|
}
|
|
|
|
public static function exercise(BaseScopedCaller $obj): string
|
|
{
|
|
return $obj::identifyProtected();
|
|
}
|
|
}
|
|
|
|
class ChildScopedCaller extends BaseScopedCaller
|
|
{
|
|
}
|
|
|