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.
41 lines
633 B
41 lines
633 B
--TEST--
|
|
Native class: construction, typed properties and direct method calls
|
|
--FILE--
|
|
<?php
|
|
|
|
#[Native]
|
|
class Point
|
|
{
|
|
public int $x = 0;
|
|
public int $y = 0;
|
|
|
|
public function __construct(int $x, int $y)
|
|
{
|
|
$this->x = $x;
|
|
$this->y = $y;
|
|
}
|
|
|
|
public function sum(): int
|
|
{
|
|
return $this->x + $this->y;
|
|
}
|
|
}
|
|
|
|
function main(): void
|
|
{
|
|
$point = new Point(20, 22);
|
|
var_dump($point->x, $point->y, $point->sum());
|
|
unset($point);
|
|
try {
|
|
$point->sum();
|
|
} catch (Error $error) {
|
|
echo "null guarded\n";
|
|
}
|
|
}
|
|
|
|
?>
|
|
--EXPECT--
|
|
int(20)
|
|
int(22)
|
|
int(42)
|
|
null guarded
|
|
|