PHP Classes – How to Create a Class with a Method Function Return

class PHPClassWithMethodAndReturn {

/*Define your variables*/
var $fname;
var $lname;

/*Create our custom function and indicate
it will be accepting two parameters.*/
function ShowInfo($fname,$lname) {

/*Passed parameters need to be assigned
values so we can use them.*/
$this->fname = $fname;
$this->lname = $lname;

/*This is how we will output the value.
will assign the final value to a return variable*/
$ret = "The name of the person is " . $this->fname;
$ret.= "The last name is " . $this->lname;

return $ret;

}

}

//create a class
$myPHPClassWithMethodAndReturn = new PHPClassWithMethodAndReturn;

//Call the method and pass two parameters and output using echo.
echo $myPHPClassWithMethodAndReturn->ShowInfo("James", "Tadeo");
?>

Testimonials

"Okay, obviously you're showing off here. NOBODY does turnaround times measured in minutes. = : ) Thanks again."
Jim Walker, James Walker Home Inspections
"THANK YOU JAMES YOU ARE INCREDIBLE! My sincerest thank you I really can't thank you enough..."
Bruno Marsala, HDMedia
"James has been a pleasure to work with. He gets stuff done efficiently, and listens to my every little gripe and comment. He's very good and I highly recommend him. "
Robert Nay, Nay Games LLC