class BlogData
{
public readonly string $title;
public readonly Status $status;
public function __construct(string $title, Status $status)
{
$this->title = $title;
$this->status = $status;
}
}
readonly class BlogData
{
public string $title;
public Status $status;
public function __construct(string $title, Status $status)
{
$this->title = $title;
$this->status = $status;
}
}
class Foo {
public function bar(mixed $entity) {
if ((($entity instanceof A) && ($entity instanceof B)) || ($entity === null)) {
return $entity;
}
throw new Exception('Invalid entity');
}
}
class Foo {
public function bar((A&B)|null $entity) {
return $entity;
}
}
null
, false
, und true
als eigene Typen RFC
RFC
class Falsy
{
public function almostFalse(): bool { /* ... */ *}
public function almostTrue(): bool { /* ... */ *}
public function almostNull(): string|null { /* ... */ *}
}
class Falsy
{
public function alwaysFalse(): false { /* ... */ *}
public function alwaysTrue(): true { /* ... */ *}
public function alwaysNull(): null { /* ... */ *}
}
use Random\Engine\Xoshiro256StarStar;
use Random\Randomizer;
$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;
// Xoshiro256**'s 'jump()' method moves the blueprint ahead 2**128 steps, as if calling
// 'generate()' 2**128 times, giving the Fiber 2**128 unique values without needing to reseed.
$blueprintRng->jump();
$fibers[] = new Fiber(function () use ($fiberRng, $i): void {
$randomizer = new Randomizer($fiberRng);
echo "{$i}: " . $randomizer->getInt(0, 100), PHP_EOL;
});
}
// The randomizer will use a CSPRNG by default.
$randomizer = new Randomizer();
// Even though the fibers execute in a random order, they will print the same value
// each time, because each has its own unique instance of the RNG.
$fibers = $randomizer->shuffleArray($fibers);
foreach ($fibers as $fiber) {
$fiber->start();
}
Die "random" Erweiterungen stellt eine neue objektorientierte API bereit, um Zufallszahlen zu generieren. Statt auf den global Seed des "random number generator (RNG)" zu setzen, welcher den Mersenne Twister Algorithmus nutzt, stellt die objektorientierte API mehrere Klassen ("Engine"s) mit modernen Algorithmen zur Verfügung, welche jeweils ihren eigenen und somit unabhängigen Seed setzen können.
Die \Random\Randomizer
Klasse stellt Funktionen bereit, um Zufallszahlen zu generieren, Arrays oder auch Strings zufällig zu mischen und viele mehr.
trait Foo
{
public const CONSTANT = 1;
}
class Bar
{
use Foo;
}
var_dump(Bar::CONSTANT); // 1
var_dump(Foo::CONSTANT); // Error
class User
{
public $name;
}
$user = new User();
$user->last_name = 'Doe';
$user = new stdClass();
$user->last_name = 'Doe';
class User
{
public $name;
}
$user = new User();
$user->last_name = 'Doe'; // Deprecated notice
$user = new stdClass();
$user->last_name = 'Doe'; // Still allowed
Das dynamische Erstellen / zuweisen von Properties wurden als veraltet markiert um Fehler zu vermeiden. Eine Klasse kann jedoch durch das Attribut #[\AllowDynamicProperties]
weiterhin die Nutzung erlauben. Die stdClass
erlaubt dynamische Properties weiterhin.
Die Nutzung von der magischen Methoden __get
/__set
sind nicht von dieser Änderung betroffen.
mysqli_execute_query
Funktion und neue mysqli::execute_query
Methode.#[\AllowDynamicProperties]
und #[\SensitiveParameter]
.ZipArchive::getStreamIndex
, ZipArchive::getStreamName
, und ZipArchive::clearError
Methoden.ReflectionFunction::isAnonymous
und ReflectionMethod::hasPrototype
Methoden.curl_upkeep
, memory_reset_peak_usage
, ini_parse_quantity
, libxml_get_external_entity_loader
, sodium_crypto_stream_xchacha20_xor_ic
, openssl_cipher_key_length
Funktionen.${}
ist als veraltet markiert.utf8_encode
und utf8_decode
sind als veraltet markiert.DateTime::createFromImmutable
und DateTimeImmutable::createFromMutable
haben nun den Rückgabetyp static
.ODBC
und PDO_ODBC
maskieren nun den Benutzernamen und das Passwort.strtolower
und strtoupper
sind nicht mehr Locale-Sensitiv.SplFileObject::getCsvControl
, SplFileObject::fflush
, SplFileObject::ftell
, SplFileObject::fgetc
, und SplFileObject::fpassthru
forcieren nun ihre Signatur.SplFileObject::hasChildren
hat nun den Rückgabetypen false
.SplFileObject::getChildren
hat nun den Rückgabetypen null
.SplFileInfo::_bad_state_ex
wurde als veraltet markiert.