Class and Function Confusion
Hi,
I was writing the code for the class to test passing of values. Here's my code.
<?php
class demo{
public function setMynum($a,$b){
$varA=$a;
$varB=$b;
return $varA;
return $varB;
}
}
$obj=new demo;
echo $obj->setMynum(12,13);
?>
Output is 12.
What is wrong with the code? I guess i have done everything to set things correct but something is missing i guess, any idea?
arunpawar
Junior Poster in Training
61 posts since Dec 2007
Reputation Points: 9
Solved Threads: 0
return stops execution of your function, and returns the specified value to the caller, thus outputting $a (which is 12). Line 8 is never executed.
What are you trying to do?
pritaeas
Posting Expert
5,484 posts since Jul 2006
Reputation Points: 653
Solved Threads: 875
Thanks I wanted to display the result. I got confused in between using return or simply echo. I think i need to understand more about return statement usage and where to and not to avoid them.
arunpawar
Junior Poster in Training
61 posts since Dec 2007
Reputation Points: 9
Solved Threads: 0