SEARCH
0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Prev | Current Page 50 | Next

Hasin Hayder

"Object-Oriented Programming with PHP5"

It's a good practice to access class properties using
accessor methods instead of directly setting or getting their value. Though accessor
methods are the same as other methods, there are some conventions writing them.
There are two types of accessor methods. One is called getter, whose purpose is
returning value of any class property. The other is setter that sets a value into a class
property. Let's see how to write the getter and setter methods for class properties:
class Student
{
private $name;
private $roll;
Chapter 2
[ 39 ]
public function setName($name)
{
$this->name= $name;
}
public function setRoll($roll)
{
$this->roll =$roll;
}
public function getName()
{
return $this->name;
}
public function getRoll()
{
return $this->roll;
}
}
?>
In the above example there are two getter methods and two setter methods. There
is a convention in writing accessor methods. A setter method should start with
set and the property name with the first character capitalized. A getter method
should start with get followed by the variable name with the first letter capitalized.
That means if we have a property named email, the getter method should be named
as getEmail and the setter method should be named as setEmail.


Pages:
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
hotel jelenia góra Russian bride Free English grammar and study guid powiekszenia wielkoformatowe counter strike 1.6