Code such as, blue to perform the display 1, red Display 6, the need is to display 6;
How can BBB () use the $c in AAA ()? Only by the way in the red box? (Feel Good Trouble)
If you don't use the same method in the red box, but there are many variables in AAA () that need to be used in BBB (), what do I do with $c?
Reply to discussion (solution)
You're a function of the argument.
If the function bbb () {} does not specify an incoming parameter when it is declared, then even if you call the time, it is useless to pass in more, always return $c that is 1. You have to specify the function parameters to be able to line.
This sentence in your BBB method.
$c = $c + 1;
There will be a notice:undefined variable:c warning ($c value is not defined)
Although you have blocked the E_notice level of error messages, it does not indicate that there are no problems. Despite the situation here,
Class Ceshi {public function aaa ($a) { $this->c = $a; $r = $this->bbb (); echo $r; } Public Function bbb () { $c = $this->c + 1; return $c; }} $XYZ = new Ceshi; $xyz->aaa (5);
This will output 6.
Use the class's properties class Ceshi {private $c; Public function aaa ($a) { $this->c = $a; echo $this->bbb (); } Public Function bbb () { return $this->c + 1; }} $XYZ = new Ceshi; $xyz->aaa (5);
Use?? The amount of sex is available.
Private $c; Any function in any of these can be used.
Class ceshi{private $c;p ublic function aaa ($a) {$this->c = $a; $k = $this->bbb (); Echo $k;} Public Function bbb () {$this->c = $this->c + 1;return $this->c;}} $XYZ = new Ceshi; $xyz->aaa (5);
Variable scope problem, 4 floor method can be used ha
Thank you upstairs!