0
I am having problem in line 29.... details is in code, can someone help me...its in PHP
3 Answers
+ 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 : )
+ 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
+ 2
Ipang It did work but why was "echo" not working?