0

I've a script with variables in a class ($slug).

When I run this script, it works, but I get a warning: Warning: Creating default object from empty value. I know, I can hide this warnings in my php.ini, but how can ik fix this warning?

    $test = new myclass();
class myclass {
    private $order;

    public function __construct() {
        $this->order = (object) NULL;
    }
    public function setVars($slug, $number) {
        $this -> order -> $slug -> number = $number;
    }

    public function getVars($slug) {
        echo $this -> order -> $slug -> number;
    }
}
$test -> setVars($slug="hello", $number=5);
$test -> getVars($slug="hello");
user2753885
  • 59
  • 2
  • 5

1 Answers1

0

Simply define order object as stdClass

public function __construct() {
    $this->order = new stdClass();
}


see this: Creating default object from empty value in PHP?

also this: http://www.php.net/manual/en/language.oop5.basic.php

Community
  • 1
  • 1
  • sorry: this doens't fix my problem... new stdClass() == (object)NULL – user2753885 Sep 24 '13 at 12:38
  • try this too: http://stackoverflow.com/questions/13323993/php-5-4-disable-warning-creating-default-object-from-empty-value –  Sep 24 '13 at 12:45