Readonly classes RFC
Doc
PHP < 8.2
class BlogData
{
public readonly string $title;
public
readonly Status $status;
public function
__construct(string $title, Status $status)
{
$this->title = $title;
$this->status = $status;
}
}
PHP 8.2
readonly class BlogData
{
public string $title;
public
Status $status;
public function
__construct(string $title, Status $status)
{
$this->title = $title;
$this->status = $status;
}
}
Disjunctive Normal Form (DNF) Types RFC
Doc
PHP < 8.2
class Foo {
public function bar(mixed $entity) {
if ($entity === null) {
return null;
}
if ((
$entity instanceof A) && ($entity instanceof B)) {
return $entity;
}
throw new
Exception('Invalid entity');
}
}
PHP 8.2
class Foo {
public function bar((A&B)|null $entity) {
if ($entity === null) {
return null;
}
return
$entity;
}
}
DNF types allow us to combine union and intersection types, following a strict rule: when combining union and intersection types, intersection types must be grouped with brackets.
Allow null
, false
, and true
as stand-alone types RFC
RFC
PHP < 8.2
class Falsy
{
public function almostFalse(): string|bool { *}
public function
almostTrue(): string|bool { *}
public function
almostNull(): string|null { *}
}
PHP 8.2
class Falsy
{
public function alwaysFalse(): false { *}
public function
alwaysTrue(): true { *}
public function
alwaysNull(): null { *}
}
New “Random” extension RFC
RFC
Doc
PHP 8.2
use RandomEngineXoshiro256StarStar;
use RandomRandomizer;$blueprintRng = new Xoshiro256StarStar(
hash('sha256', "Example seed that is converted to a 256 Bit string via SHA-256", true)
);$fibers = [];
for ($i = 0; $i < 8; $i++) {
$fiberRng = clone $blueprintRng;
$blueprintRng->jump();$fibers[] = new Fiber(function () use ($fiberRng, $i): void {
$randomizer = new Randomizer($fiberRng);
echo
"{$i}: " . $randomizer->getInt(0, 100), PHP_EOL;
});
}$randomizer = new Randomizer();$fibers = $randomizer->shuffleArray($fibers);
foreach ($fibers as $fiber) {
$fiber->start();
}