Problems when calling private function test() through public function getSalary()
孙痴慢
孙痴慢 2018-10-12 06:40:47
0
4
1027

public function getSalarya()

{

$res = $this->test();

return $res;

}


## private function test(){

$res = $this->salary;

if ($this-> dept == 'Finance Department') {

          $res = 'How dare you check the people around the boss? You don't want to mess around anymore';

}

孙痴慢
孙痴慢

reply all(2)
孙痴慢

It is around 18:26 in the video. We use test() to encapsulate the filtering mechanism of the previous if statement, and then use the public getSalary() to call the private test(). I found that salary getSalary() did not return the value we needed to get. Later I found that getSalary() wants to return a value, so it needs to return the value through return in getSalary(). Return $res; is no problem. But the value passed by test() must be received through the variable $res in getSalary(). Just write $res = $this->test(); and then go back and check test(), and find that test() also needs a return to pass out $res in test(). Just add return $res; in test() and it will run.  

  • reply The 4 pictures I added are missing. . .
    孙痴慢 author 2018-10-13 12:33:35
Peter-Zhu

Can you at least tell me what the problem is? How can I help you answer it?

  • reply Sorry, Teacher Zhu. Let me rearrange it
    孙痴慢 author 2018-10-13 09:04:33
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template