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 和 true 作为独立类型 RFC RFCclass 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();
}"random" 扩展提供了一个新的面向对象 API 用于随机数生成。它不再依赖于使用梅森旋转算法的全局种子随机数生成器 (RNG),而是提供了一个面向对象的 API,其中包含多个类 ("Engine"),这些类允许访问现代算法,这些算法将其状态存储在对象中,从而允许多个独立的可播种序列。
\Random\Randomizer 类提供了一个高级接口,用于使用引擎的随机性生成随机整数、随机排列数组或字符串、选择随机数组键等等。
trait Foo
{
public const CONSTANT = 1;
}
class Bar
{
use Foo;
}
var_dump(Bar::CONSTANT); // 1
var_dump(Foo::CONSTANT); // 错误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'; // 弃用通知
$user = new stdClass();
$user->last_name = 'Doe'; // 仍然允许创建动态属性已被弃用,以帮助避免错误和拼写错误,除非类通过使用 #[\AllowDynamicProperties] 属性选择加入。stdClass 允许动态属性。
__get/__set 魔术方法的使用不受此更改的影响。
mysqli_execute_query 函数和 mysqli::execute_query 方法。#[\AllowDynamicProperties] 和 #[\SensitiveParameter] 属性。ZipArchive::getStreamIndex、ZipArchive::getStreamName 和 ZipArchive::clearError 方法。ReflectionFunction::isAnonymous 和 ReflectionMethod::hasPrototype 方法。curl_upkeep、memory_reset_peak_usage、ini_parse_quantity、libxml_get_external_entity_loader、sodium_crypto_stream_xchacha20_xor_ic、openssl_cipher_key_length 函数。${} 字符串插值。utf8_encode 和 utf8_decode 函数。DateTime::createFromImmutable 和 DateTimeImmutable::createFromMutable 的尝试返回类型为 static。ODBC 和 PDO_ODBC 对用户名和密码进行转义。strtolower 和 strtoupper 不再对区域设置敏感。SplFileObject::getCsvControl、SplFileObject::fflush、SplFileObject::ftell、SplFileObject::fgetc 和 SplFileObject::fpassthru 强制执行其签名。SplFileObject::hasChildren 的尝试返回类型为 false。SplFileObject::getChildren 的尝试返回类型为 null。SplFileInfo::_bad_state_ex 已被弃用。