Creating default object from empty value:PHP 5.4
I am getting an error like Creating default object from empty value on line 196($settings->{$v->Name} = $setting; ). I think, it's because I have upgraded php to 5.4 version. So that I have set $setting =(object) null instead of $setting =null. But i couldn't correct it on line 196($settings->{$v->Name} = $setting;).
$settings;
foreach($SettingsRows as $v)
{
$setting =(object) null;
$setting->ID = $v->ID;
$setting->Name = $v->Name;
$setting->Value = $v->Value;
$setting->Class = $v->ClassName;
$setting->Form = new $setting->Class($setting);
$settings->{$v->Name} = $setting;
}
How can I set $setting value to $settings->{$v->Name} ? What I need to change here?
Thanks!
Your code looks sketchy, but apparently you need $settings = new stdClass
before the foreach
loop. ( new stdClass
is the same thing as (object) null
, but more clear in my opinion.)
And it really looks like $settings
ought to just be an array (eg, $settings[$v->Name] = $setting;
), but I have no idea what you are trying to do.
用PHP 5.4为我工作
$query1 = $this->db()->prepare('SELECT id,title FROM category');
$query1->execute();
$d['query1']=(object) null;
foreach($query1->fetchAll(PDO::FETCH_OBJ) as $k=>$v){
$d['query1']->$k=$v;
$query2 = $this->db()->prepare('SELECT id,title FROM page');
$query2->execute();
$d['query2']=(object) null;
foreach($query2->fetchAll(PDO::FETCH_OBJ) as $k=>$v){
$d['query2']->$k=$v;
}
}
return $d;
链接地址: http://www.djcxy.com/p/59390.html
上一篇: 升级我的php5.4从空值创建默认对象后
下一篇: 从空值创建默认对象:PHP 5.4