2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

php7.4から配列でない値に配列のようにアクセスしたらエラーになる

Posted at

php7.3からphp7.4への下位互換性のない変更点の1つとして
配列じゃない値に配列のようにアクセスすることができなくなりました。

ちなみにnullに対して以下のようにアクセスすると以下のようになります。

$hoge = null;
var_dump($hoge[0]);
exit;
出力結果
// php7.3まで
NULL

// php7.4
Trying to access array offset on value of type null in /hoge.php on line 3 trace => #0 ...

null, bool, int, float または resource 型を ($null["key"] のように) 配列としてアクセスしようとすると、警告が生成されるようになりました。

地味ですが、今までがよしなに動き過ぎていて、影響範囲が大きめの割と面倒な対応でした。

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?