0

I am having problem in line 29.... details is in code, can someone help me...its in PHP

https://code.sololearn.com/wCjXF2rxavEA/?ref=app

11th Aug 2018, 8:45 AM
Rashim Narayan Tiku
Rashim Narayan Tiku - avatar
3 odpowiedzi
+ 3
Rashim Narayan Tiku 'echo' works, it's just when you do ... echo "Voice of dog is " . $dog->speak(); PHP calls the speak function, and expected a return value to be concatenated with "Voice of dog is ", but speak function didn't return anything, instead, it calls 'echo' internally, so there is nothing to be concatenated with "Voice of dog is ". I hope that clears the doubt, I'm not very good trying to explain things, and I'm not English speaking naturally : )
11th Aug 2018, 10:38 AM
Ipang
+ 5
Use return in speak function instead of echo, as follows: function speak(){ return $this -> voice; } If you want to use echo, call the function on its own rather than concatenating it with "Voice of dog is ", as follows: echo "Voice of dog is "; $dog->speak(); Hth, cmiiw
11th Aug 2018, 9:23 AM
Ipang
+ 2
Ipang It did work but why was "echo" not working?
11th Aug 2018, 10:09 AM
Rashim Narayan Tiku
Rashim Narayan Tiku - avatar