interface I {
    // We may naively assume that the PHP constant is always a string.
    const PHP = 'PHP 8.2';
}
class Foo implements I {
    // But implementing classes may define it as an array.
    const PHP = [];
}interface I {
    const string PHP = 'PHP 8.3';
}
class Foo implements I {
    const string PHP = [];
}
// Fatal error: Cannot use array as value for class constant
// Foo::PHP of type stringclass Foo {
    const PHP = 'PHP 8.2';
}
$searchableConstant = 'PHP';
var_dump(constant(Foo::class . "::{$searchableConstant}"));class Foo {
    const PHP = 'PHP 8.3';
}
$searchableConstant = 'PHP';
var_dump(Foo::{$searchableConstant});アトリビュート#[\Override]の追加                RFC
            use PHPUnit\Framework\TestCase;
final class MyTest extends TestCase {
    protected $logFile;
    protected function setUp(): void {
        $this->logFile = fopen('/tmp/logfile', 'w');
    }
    protected function taerDown(): void {
        fclose($this->logFile);
        unlink('/tmp/logfile');
    }
}
// The log file will never be removed, because the
// method name was mistyped (taerDown vs tearDown).use PHPUnit\Framework\TestCase;
final class MyTest extends TestCase {
    protected $logFile;
    protected function setUp(): void {
        $this->logFile = fopen('/tmp/logfile', 'w');
    }
    #[\Override]
    protected function taerDown(): void {
        fclose($this->logFile);
        unlink('/tmp/logfile');
    }
}
// Fatal error: MyTest::taerDown() has #[\Override] attribute,
// but no matching parent method exists#[\Override]を追加すると、親クラスもしくはインターフェイスに同じメソッドが定義されていることを確認します。これにより、メソッドを意図的にオーバーライドしていると明示することができ、また親メソッドが変更されたときに検出できます。            class PHP {
    public string $version = '8.2';
}
readonly class Foo {
    public function __construct(
        public PHP $php
    ) {}
    public function __clone(): void {
        $this->php = clone $this->php;
    }
}
$instance = new Foo(new PHP());
$cloned = clone $instance;
// Fatal error: Cannot modify readonly property Foo::$phpclass PHP {
    public string $version = '8.2';
}
readonly class Foo {
    public function __construct(
        public PHP $php
    ) {}
    public function __clone(): void {
        $this->php = clone $this->php;
    }
}
$instance = new Foo(new PHP());
$cloned = clone $instance;
$cloned->php->version = '8.3';readonlyプロパティをクローンする際、__cloneメソッド内で一度だけプロパティを変更できるようになりました。            json_validate()の追加                RFC
                ドキュメント
            function json_validate(string $string): bool {
    json_decode($string);
    return json_last_error() === JSON_ERROR_NONE;
}
var_dump(json_validate('{ "test": { "foo": "bar" } }')); // truevar_dump(json_validate('{ "test": { "foo": "bar" } }')); // truejson_validate()は、json_decode()よりも効率的にJSONが正しい形式かをチェックすることができます。            Randomizer::getBytesFromString()の追加                RFC
                ドキュメント
            // This function needs to be manually implemented.
function getBytesFromString(string $string, int $length) {
    $stringLength = strlen($string);
    $result = '';
    for ($i = 0; $i < $length; $i++) {
        // random_int is not seedable for testing, but secure.
        $result .= $string[random_int(0, $stringLength - 1)];
    }
    return $result;
}
$randomDomain = sprintf(
    "%s.example.com",
    getBytesFromString(
        'abcdefghijklmnopqrstuvwxyz0123456789',
        16,
    ),
);
echo $randomDomain;// A \Random\Engine may be passed for seeding,
// the default is the secure engine.
$randomizer = new \Random\Randomizer();
$randomDomain = sprintf(
    "%s.example.com",
    $randomizer->getBytesFromString(
        'abcdefghijklmnopqrstuvwxyz0123456789',
        16,
    ),
);
echo $randomDomain;Randomizer::getFloat()とRandomizer::nextFloat()の追加                RFC
                ドキュメント
            // Returns a random float between $min and $max, both including.
function getFloat(float $min, float $max) {
    // This algorithm is biased for specific inputs and may
    // return values outside the given range. This is impossible
    // to work around in userland.
    $offset = random_int(0, PHP_INT_MAX) / PHP_INT_MAX;
    return $offset * ($max - $min) + $min;
}
$temperature = getFloat(-89.2, 56.7);
$chanceForTrue = 0.1;
// getFloat(0, 1) might return the upper bound, i.e. 1,
// introducing a small bias.
$myBoolean = getFloat(0, 1) < $chanceForTrue;$randomizer = new \Random\Randomizer();
$temperature = $randomizer->getFloat(
    -89.2,
    56.7,
    \Random\IntervalBoundary::ClosedClosed,
);
$chanceForTrue = 0.1;
// Randomizer::nextFloat() is equivalent to
// Randomizer::getFloat(0, 1, \Random\IntervalBoundary::ClosedOpen).
// The upper bound, i.e. 1, will not be returned.
$myBoolean = $randomizer->nextFloat() < $chanceForTrue;浮動小数点演算はその精度や丸め要素により、偏りのない乱数を生成することは比較的高難度であり、よく見られるユーザランド実装は結果が偏っていたり範囲外になっていたりすることがよくあります。
Randomizerエクステンションでは普遍的な浮動小数乱数を生成するために2つのメソッドが実装されました。Randomizer::getFloat()はDrawing Random Floating-Point Numbers from an Interval. Frédéric Goualard・ACM Trans. Model. Comput. Simul.・32:3・2022.という論文で紹介されたγ-sectionというアルゴリズムで乱数を生成します。
php -l foo.php bar.php
No syntax errors detected in foo.php
                        
                    
php -l foo.php bar.php
No syntax errors detected in foo.php
No syntax errors detected in bar.php
                        
                    コマンドラインLinterに複数のファイルを渡せるようになりました。
DOMElement::getAttributeNames()・DOMElement::insertAdjacentElement()・DOMElement::insertAdjacentText()・DOMElement::toggleAttribute()・DOMNode::contains()・DOMNode::getRootNode()・DOMNode::isEqualNode()・DOMNameSpaceNode::contains()・DOMParentNode::replaceChildren()メソッドが追加されました。IntlCalendar::setDate()・IntlCalendar::setDateTime()・IntlGregorianCalendar::createFromDate()・IntlGregorianCalendar::createFromDateTime()が追加されました。ldap_connect_wallet()・ldap_exop_sync()が追加されました。mb_str_pad()が追加されました。posix_sysconf()・posix_pathconf()・posix_fpathconf()・posix_eaccess()が追加されました。ReflectionMethod::createFromMethodName()が追加されました。socket_atmark()が追加されました。str_increment()・str_decrement()・stream_context_set_options()が追加されました。ZipArchive::getArchiveFlag()が追加されました。zend.max_allowed_stack_sizeが追加されましたnから始めた場合、次の自動採番は0ではなくn + 1になりました。range()関数の挙動が変更になりました。U_MULTIPLE_DECIMAL_SEPERATORSは非推奨になりました。U_MULTIPLE_DECIMAL_SEPARATORSを使いましょう。MT_RAND_PHPは非推奨になりました。ReflectionClass::getStaticProperties()の返り値がnull許容型ではなくなりました。assert.active・assert.bail・assert.callback・assert.exception・assert.warningは非推奨になりました。get_class()とget_parent_class()は引数が必須になりました。