sealed class Option permits Some, None { ... }
class Some extends Option { ... } // ok
class None extends Option { ... } // ok
class Maybe extends Option { ... } // Fatal error: cannot extend sealed class
readonly class Foo
{
public int $bar;
public function __construct() {
$this->bar = 1;
}
}
$foo = new Foo();
$foo->bar = 2;
// Fatal Error: Uncaught Error: Cannot modify readonly property Foo::$bar
$foo->baz = 1;
// Fatal Error: Uncaught Error: Cannot create dynamic property Foo::$baz
// As of 8.0:
$y = 1;
$fn1 = fn($x) => $x + $y; // auto-capture + single expression
$fn2 = function ($x) use ($y): int { // manual-capture + statement list
// ...
return $x + $y;
};
// With multi line arrow fns
$fn3 = fn ($x): int { // auto-capture + statement list
// ...
return $x + $y;
};