Quantcast
Channel: php – PHP Web Developer
Viewing all articles
Browse latest Browse all 12

Simple Object Oriented example in PHP

$
0
0

class Person
{
    var $name;
    
    public function getName()
    {
        return $this->name;
    }
    
    public function setName($name)
    {
        $this->name = $name;
    }
    
}

function changeName($person, $name)
{
    $person->setName($name);
}

$obj = new Person("Milap");

$val = changeName($obj, "Patel");

print $obj->getName();


Output :-

Patel

Filed under: php Tagged: php

Viewing all articles
Browse latest Browse all 12

Trending Articles