M
M
MdaUZH2017-01-28 20:53:39
PHP
MdaUZH, 2017-01-28 20:53:39

Initializing a class in a constructor?

Hi everyone there is:

class One extends Two{
public $obj;

public function __construct($param){
    parent::_construct($param);
    $obj = new Three();
}

public function obj_print(){
    var_dump($obj); // NULL
}
}

Why is the class not initialized in the constructor?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Novikov, 2017-01-28
@MdaUZH

In functions use $this->obj instead of $obj
php.net/manual/en/language.oop5.basic.php

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question