以下の内容はhttps://iww.hateblo.jp/entry/20240530/propertyより取得しました。


PHPで、空の変数にプロパティを追加すると エラーになる

<?php

$o->a = "hello";
print_r($o);

こういうプログラムを実行すると、5.xや7.xの頃はエラーではなくWarningどまりだったが
8.xではすべてFatal errorになった。

PHP7.xのとき
Warning: Creating default object from empty value in /tmp/hoge.php on line 3
stdClass Object
(
    [a] => hello
)
PHP8.xのとき
Fatal error: Uncaught Error: Attempt to assign property "a" on null in /tmp/hoge.php:3
Stack trace:
#0 {main}
  thrown in /tmp/hoge.php on line 3


ちゃんと横着せずに

<?php

$o = new stdClass;
$o->a = "hello";
print_r($o);


qiita.com
stackoverflow.com




以上の内容はhttps://iww.hateblo.jp/entry/20240530/propertyより取得しました。
このページはhttp://font.textar.tv/のウェブフォントを使用してます

不具合報告/要望等はこちらへお願いします。
モバイルやる夫Viewer Ver0.14