Ian Littman
Thanks to release managers Ben Ramsey, Pierrick Charron, and Sergey Panteleev
brew tap shivammathur/php
brew install php@8.2
class Post { public readonly string $title; public readonly Status $status; // snip }
readonly class Post
{
public string $title;
public Status $status;
// snip
}
This also disables dynamic properties and untyped properties (use "mixed")
nextInt(): int
getInt(int $min, int $max): int
getBytes(int $length): string
shuffleArray(array $array): array
shuffleBytes(string $bytes): string
pickArrayKeys(array $array, int $num): array
__serialize()/__unserialize()
namespace Random; interface Engine { public function generate(): string; } interface CryptoSafeEngine extends Engine {}
Non-crypto-safe, seedable Engines
Mt19937 (Mersenne Twister, from mt_rand)
function login(
string $user,
#[\SensitiveParameter] string $password
) {
// …
throw new Exception('Error');
}
login('root', 'root');
Fatal error: Uncaught Exception: Error in login.php:8
Stack trace:
#0 login.php(11): login('root', Object(SensitiveParameterValue))
#1 {main}
thrown in login.php on line 8
enum A: string
{
case B = 'B';
const C = [self::B->value => self::B];
}
Useful primarily for array keys mapping to enum names/values