オブジェクトの存在しないプロパティを参照したときの挙動
もしかしてオブジェクトの場合もか?ということで試したメモ。
Main.php
<?php ini_set('error_reporting', E_ALL); ini_set('display_errors', 1); class A { public $a = null; } $a = new A(); var_dump($a->a); var_dump($a->b);
実行結果。
$ for php in php56 php70 php71 php72 php73 php74 php80 php81 php82 ; do echo "===${php}===" ; ${php} Main.php ; done ===php56=== NULL PHP Notice: Undefined property: A::$b in /home/hhelibex/blog/2022-0614-01/Main.php on line 11 Notice: Undefined property: A::$b in /home/hhelibex/blog/2022-0614-01/Main.php on line 11 NULL ===php70=== NULL PHP Notice: Undefined property: A::$b in /home/hhelibex/blog/2022-0614-01/Main.php on line 11 Notice: Undefined property: A::$b in /home/hhelibex/blog/2022-0614-01/Main.php on line 11 NULL ===php71=== NULL PHP Notice: Undefined property: A::$b in /home/hhelibex/blog/2022-0614-01/Main.php on line 11 Notice: Undefined property: A::$b in /home/hhelibex/blog/2022-0614-01/Main.php on line 11 NULL ===php72=== NULL PHP Notice: Undefined property: A::$b in /home/hhelibex/blog/2022-0614-01/Main.php on line 11 Notice: Undefined property: A::$b in /home/hhelibex/blog/2022-0614-01/Main.php on line 11 NULL ===php73=== NULL PHP Notice: Undefined property: A::$b in /home/hhelibex/blog/2022-0614-01/Main.php on line 11 Notice: Undefined property: A::$b in /home/hhelibex/blog/2022-0614-01/Main.php on line 11 NULL ===php74=== NULL PHP Notice: Undefined property: A::$b in /home/hhelibex/blog/2022-0614-01/Main.php on line 11 Notice: Undefined property: A::$b in /home/hhelibex/blog/2022-0614-01/Main.php on line 11 NULL ===php80=== NULL PHP Warning: Undefined property: A::$b in /home/hhelibex/blog/2022-0614-01/Main.php on line 11 Warning: Undefined property: A::$b in /home/hhelibex/blog/2022-0614-01/Main.php on line 11 NULL ===php81=== NULL PHP Warning: Undefined property: A::$b in /home/hhelibex/blog/2022-0614-01/Main.php on line 11 Warning: Undefined property: A::$b in /home/hhelibex/blog/2022-0614-01/Main.php on line 11 NULL ===php82=== NULL PHP Warning: Undefined property: A::$b in /home/hhelibex/blog/2022-0614-01/Main.php on line 11 Warning: Undefined property: A::$b in /home/hhelibex/blog/2022-0614-01/Main.php on line 11 NULL $
配列の場合と同様に、PHP 8.0から「Warning」に変わっている。