Creating default object from empty value in PHP?

Posted 迷失之路

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Creating default object from empty value in PHP?相关的知识,希望对你有一定的参考价值。

 

Your new environment may have E_STRICT warnings enabled in error_reporting if it is php <= 5.3, or if simply have error_reporting set to at least E_WARNING with PHP 5.4+. . That error is triggered when $res is NULL or not yet initialized:

$res = NULL;
$res->success = false; // Warning: Creating default object from empty value

PHP will report a different error message if $res is already initialized to some value but is not an object:

$res = 33;
$res->success = false; // Warning: Attempt to assign property of non-object

In order to comply with E_STRICT standards prior to PHP 5.4, or the normal E_WARNING error level in PHP >= 5.4, assuming you are trying to create a generic object and assign the property success, you need to declare $res as an object of stdClass:

$res = new stdClass();
$res->success = false;

来自http://stackoverflow.com/questions/8900701/creating-default-object-from-empty-value-in-php

以上是关于Creating default object from empty value in PHP?的主要内容,如果未能解决你的问题,请参考以下文章

Effective Java P2 Creating and Destroying Objects

Creating objects on stack or heap

(Les10 Creating Other Schema Object)[20171213]

launch_map: "Dict[asyncio.Task[object], threading.Thread]" = ​​ -Error While Creating Djan

Pixhawk2.1 开发板变异

How do you stop Ansible from creating .retry files in the home directory?