Constructor problem???
Presumably, the class B method uses a lot of object instances of Class A, so I instantiate class A directly inside the class B constructor.
Class a{
Public $mes = "OK";
}
Class b{
Public Function __construct () {
Many of the following methods are used to the object of a, so I in the Class B constructs a direct object, convenient to call
$a =new A ();
The member method of the following B begins to invoke the method of the A object
Public Function test () {
$mes = $a->mes;
The code runs here to prompt $ A to not know what the thing is, that is, there is no instantiation, but I did not do it on the constructor? It doesn't seem to work.
Echo $mes;
}
$b =new B ();
$b->test ();
}
I instantiate the A object in the constructor of B, the member method of B is not used, what's going on? I have a lot of members behind the method is to use a object Ah, can not be a one to instantiate oh.
Share to:
------Solution--------------------
Scope Problem of variables
$this->a = new A ();
$mes = $this->a->mes;