OOP in PHP
Method and Parameters
The method members of the class can accept parameters. The values of the
parameters will be passed to the methods. You can define the parameters
of the methods by putting them in braces, and separating them with
commas.
Example:
<?php
class Employee
{
//data members
var $emp_id="";
var $emp_name="";
var $emp_sex="";
var $emp_salary="";
//method members
function setName($name){ //$name is the parameter
$this->emp_name=$name;
}
function getName(){
return $this->emp_name;
}
}
$emp=new Employee();//create object
$emp->setName("Dara Yuk");//supply value to the parameter
echo "Name:".$emp->getName();//display the name
?>
|