PHP 8.2 Features
Readonly Classes
readonly class ValueObject {
public function __construct(
public string \$name,
public int \$value,
) { }
}
Disjunctive Normal Form Types
// Intersection types combined with union types
function process(
(Countable&ArrayAccess)|string \$input
): void { }
Randomizer Extension
\$random = new \Random\Randomizer();
\$num = \$random->getInt(1, 100);
\$bytes = \$random->getBytes(16);
\$shuffled = \$random->shuffleArray(\$items);
PHP 8.3 Features
json_validate()
if (json_validate(\$jsonString)) {
\$data = json_decode(\$jsonString);
}
Override Attribute
class Child extends Parent {
#[\\Override]
public function method(): void { ... }
}
Dynamic class constant fetch
echo \$className::\$constantName;