I’m new to php so the question is dump. Take a look at the following code
class A {
private $obj;
public function A() {
$this->obj = new Obj();
//$this->obj->fff() works here;
//still var_dump($this->obj) prints NULL here
}
public f() {
//$this->obj is NULL here!!!
//$this->obj->ff() throws an error
}
}
UPD in f() I get Fatal error: Call to a member function ff() on a non-object in ...
how should I init $obj to see it in f()?
Thank you in advance!!
Try the following:
I think the problem is you missed
function. I am not really aPHPguy but I thinkpublic function A()will work too, but the__constructis preferred.Edit: Now you added
function. I am not really sure if my answer will help you then.