<?php
declare(strict_types=1);
class Foo
{
public int $id;
public string $name;
}
try {
$foo = new Foo();
// Wrong type
try {
$foo->id = 'text for integer type';
} catch (Error $e) {
dump($e->getMessage());
}
// Some unset properies
$foo->id = 1;
try {
echo $foo->name;
} catch (Error $e) {
dump($e->getMessage());
}
// callable
$foo->name = '5';
try {
$foo->func = function () {
echo 'Hello world.';
};
($foo->func)();
} catch (Error $e) {
dump($e->getMessage());
}
} catch (Throwable $e) {
dump($e->getMessage());
}
^ "Cannot assign string to property Foo::$id of type int"
^ "Typed property Foo::$name must not be accessed before initialization"