php 8.0 code example
Example 1: php 8
latest version of php.
see new features at https:
Example 2: php8
class Number {
public function __construct(
private int|float $number
) {}
}
new Number('NaN');
Example 3: php8
class Point {
public function __construct(
public float $x = 0.0,
public float $y = 0.0,
public float $z = 0.0,
) {}
}
Example 4: php8
$country = $session?->user?->getAddress()?->country;
$country = null;
if ($session !== null) {
$user = $session->user;
if ($user !== null) {
$address = $user->getAddress();
if ($address !== null) {
$country = $address->country;
}
}
}