search

Home  >  Q&A  >  body text

Problems when calling private function test() through public function getSalary()

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';

}

孙痴慢孙痴慢2268 days ago1029

reply all(4)I'll reply

  • 孙痴慢

    孙痴慢2018-10-13 12:32:21

    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
    0
  • 孙痴慢

    The 4 pictures I added are missing. . .

    孙痴慢 · 2018-10-13 12:33:35
  • 天蓬老师

    天蓬老师2018-10-13 08:52:54

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

    reply
    0
  • 孙痴慢

    Sorry, Teacher Zhu. Let me rearrange it

    孙痴慢 · 2018-10-13 09:04:33
  • Cancelreply