Code Area

Simple example of Object Oriented Programming (OOP) in PHP

This is very basic example of object oriented programming.

class MyClass{    //Creating a Class name MyClass
    private $Name , $Age , $Address;

    public function setInfo($Name , $Age , $Address){
        $this->Name = $Name;
        $this->Age = $Age;
        $this->Address = $Address;

    public function getInfo(){
        return 'Name : '.$this->Name. ' <br/>Age : '. $this->Age. ' 
        <br/>Address : '.$this->Address;

$Obj = new MyClass();
$Obj->setInfo('Your Name', 25 , 'Your Address');
echo $Obj->getInfo();


By Sohel Rana

PHP Programmer, Software Engineer & Technology lover

Leave a Reply

Your email address will not be published. Required fields are marked *