PHP 7.2.x から PHP 7.3.x への移行の勝手な日本語訳 後方互換のない変更④
PHP 7.2.x から PHP 7.3.x への移行の日本語訳がないので勝手に翻訳して備忘録にする。
https://www.php.net/manual/ja/migration73.incompatible.php
Static Properties no longer separated by Reference Assignment
静的プロパティは参照代入で分離されなくなりました
In PHP, static properties are shared between inheriting classes, unless the static property is explicitly overridden in a child class. However, due to an implementation artifact it was possible to separate the static properties by assigning a reference. This loophole has been fixed.
PHPでは、静的プロパティが子クラスで明示的にオーバーライドされない限り、静的プロパティは継承クラス間で共有されます。 ただし、実装の成果物のため、参照を割り当てることで静的プロパティを分離することができました。 この抜け穴は修正されました。
<?php
class Test {
public static $x = 0;
}
class Test2 extends Test { }
Test2::$x = &$x;
$x = 1;
var_dump(Test::$x, Test2::$x);
// Previously: int(0), int(1)
// Now: int(1), int(1)
?>
つづいて
References returned by Array and Property Accesses are immediately unwrapped
ArrayおよびProperty Accessから返された参照は、すぐに展開されます
References returned by array and property accesses are now unwrapped as part of the access. This means that it is no longer possible to modify the reference between the access and the use of the accessed value:
配列およびプロパティアクセスによって返される参照は、アクセスの一部としてラップ解除されるようになりました。 これは、アクセスとアクセスされた値の使用との間の参照を変更することがもはや不可能であることを意味します。
<?php
$arr = [1];
$ref =& $arr[0];
var_dump($arr[0] + ($arr[0] = 2));
// Previously: int(4), Now: int(3)
?>
This makes the behavior of references and non-references consistent. Please note that reading and writing a value inside a single expression remains undefined behavior and may change again in the future.
これにより、参照と非参照の動作が一致します。 単一の式の中で値を読み書きすることは未定義の動作のままであり、将来再び変わるかもしれないことに注意してください。
つづいて
Argument Unpacking of Traversables with non-Integer Keys no longer supported
整数キー以外のTraversableの引数展開はサポートされなくなりました
Argument unpacking stopped working with Traversables with non-integer keys. The following code worked in PHP 5.6-7.2 by accident.
引数の展開が、整数以外のキーを持つTraversablesで動作しなくなりました。 次のコードは偶然にPHP 5.6-7.2で動きました。
<?php
function foo(...$args) {
var_dump($args);
}
function gen() {
yield 1.23 => 123;
}
foo(...gen());
?>
|