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

时间: 2024-09-30 20:56:16

Creating default object from empty value in PHP?的相关文章

hp警告Creating default object from empty value 问题的解决方法

hp警告Creating default object from empty value 问题的解决方法 解决方法是找到报错的位置然后看哪个变量是没有初始化而直接使用的,将这个变量先实例化一个空类.如: 复制代码 代码如下: $ct = new stdClass(); 修改文件相应代码,如: 复制代码 代码如下: if ( ! isset( $themes[$current_theme] ) ) { delete_option( 'current_theme' ); $current_theme

Warning Creating default object from empty value in xxx.php

PHP 提示 Creating default object from empty value 的问题,一般是由于PHP版升级的原因,PHP 5.4 以上的版本一般会报这个错误: 我的解决方法:找到报错的地方,初始化对象 $_obj = new stdClass(); 同理,数组也需要初始化 $_arr = array(); 变量则不需要(我测试过). Warning Creating default object from empty value in xxx.php

NET:Error Creating Control -&quot;Object Reference Not Set To An Instance Of Object&quot;

这几天,竟遇见些奇葩问题,有的实在懒的写了,这个比较有意思,以前没见过,写个文章记录下: Error Creating Control -"Object Reference Not Set To An Instance Of Object" 在winforms页面中,所有page的所有服务器控件的位置出现一行红字"Error Creating Control - Object reference not set to an instance of an object"

Avoid exception: Have no modify permission on Team when creating business object.

~~~~~~~~~~Background~~~~~~~~~~ If using API to create a business object for a non-administrative account, then an exception may occur like this: the current user don't have the modify permission on team. ~~~~~~~~~~Solution~~~~~~~~~~ 1. Add ACL to dom

Creating InetAddress object in Java

I am trying to convert an address specified by an IP number or a name, both in String (i.e. localhost or 127.0.0.1), into an InetAdress object. There's no constructor but rather static methods that return an InetAddress. So if I get a host name it's

WordPress无法新发布文章和页面,提示您正在编辑展示最新文章的页面

WordPress发布新文章和页面时显示“您正在编辑展示最新文章的页面.” 最近由用户遇到了这个问题,正常编辑文章时,数据库卡死,重启服务器之后,点击新发布文章,主编辑器消失,并提示“您正在编辑展示最新文章的页面.” 进入到发布新文章或者新页面时,顶部还有一个报错:Creating default object from empty value 当你点击发布文章时会有提示:您没有修改这篇文章的权限. 经过一番查阅资料,目前这个问题已经解决,由于此问题不是很常见,因此资料会比较少,在此我们将解决方

Object.create(): the New Way to Create Objects in JavaScript

There are a lot of ways to create Objects in JavaScript, perhaps even more to integrate inheritance into them. Just when you thought that you've seen every possible way to create JS objects, I'm here to announce that there's yet another: the new Obje

ECMAScript6 Object

二.对象 A lot of ECMAScript 6 focused on improving the utility of objects. The focus makes sense given that nearly every value in JavaScript is represented by some type of object. Additionally, the number of objects used in an average JavaScript program

Different ways to create an object in Java

Different ways to create an object in Java You must have used the “new” operator to create an Object of a Class. But is it the only way to create an Object? Simple Answers is NO, then in how many ways we can create Object of a Class. There are severa