Pages

Translate

Sunday, 20 January 2013

Tutorial 1 :Object(Declaring a Class)


In This Tutorial ,You are going to learn creating a Object.

    Here is a example of object :

     <?php
class Person{
    private $name;   
//Main point 1
    function setName($name){
        $this->name=$name;
    }
    function getName(){
        return $this->name;
    }
   
}

$judy= new Person();
$judy->setName("Judy");

$joe= new Person();
$joe->setName("Joe");

print $judy->getName()."\n";
print $joe->getName()."\n";
?> 




Output:
JudyJoe

 
      Main point 1 : we used the private Keyword,it basically means that only methods in this class can access $name. it forces anyone wanting to get/set this property to use the getName() and setName() methods,which represent the class's interface for use by other objects or source code.

Download for this Toturial

No comments:

Post a Comment