0

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!

2 Answers 2

1

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 (e.g., $settings[$v->Name] = $setting;), but I have no idea what you are trying to do.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for your reply. I set $settings = new stdClass before the foreach loop.
0

Work for me with 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;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.