PHP class
Class A {public $a =0; Public Fucntion Ax () { $this->a= ' 111 '; } Public Fucntion bx () { echo $this->a; }}
How can I call a $ A value equal to 111 in BX () after the $a is assigned in AX ()? After assigning a property to one of the methods, the other method cannot get the value.
Reply to discussion (solution)
Your function has been wrongly written ....
AX,BX is executed sequentially after instantiation.
You have to understand that AX/BX is parallel within the class, not that you write in front, and that the back has values
Class A {public $a =0; Public Fucntion A () { $this->a= ' 111 '; } Public Fucntion bx () { echo $this->a; }}
Copy my code and run it. function spelling error, modify it yourself.
Class A {public $a =0; Public function A () { return $this->a= ' 111 '; } Public Function bx () { echo $this->a (); }} $p = new A (); $p->bx ();