1,
class Number {
private int|float $number;
public function setNumber(int|float $number): void {
$this->number = $number;
}
public function getNumber(): int|float {
return $this->number;
}
}
2,
class BookStore
{
public function __construct(
private string $name = ‘The Alchemist’,
private string $author = ‘Paulo Coelho’
) {
try {
throw new Exception(‘foo!’);
} catch (Exception) {
// send a predefined email to the administrator
// irrespective of the exception information
}
}
}
3
class A
{
// no type is specified, mixed type is assumed