Access Modifier

 <?php

// PUBLIC ACCESS MODIFIER
// class Base
// {
//     public $name;

//     public function __construct($n)
//     {
//         $this->name = $n;
//     }
//     public function show()
//     {
//         echo "Your Name : " . $this->name . "<br>";
//     }
// }
// $test = new Base("Yahoo Baba");
// $test->name = "Baba Yahoo";
// $test->show();

// PROTECTED ACCESS MODIFIER
// class Base
// {
//     protected $name;

//     public function __construct($n)
//     {
//         $this->name = $n;
//     }
//     protected function show()
//     {
//         echo "Your Name : " . $this->name . "<br>";
//     }
// }
// class Derived extends Base
// {
//     public function get()
//     {
//         echo "Your Name is : " . $this->name . "<br>";
//     }
// }

// $test = new Derived("Yahoo Baba");
// // $test->name = "Baba Yahoo";
// $test->get();

//  PRIVATE ACCESS MODIFIER
class Base
{
    private $name;

    public function __construct($n)
    {
        $this->name = $n;
    }
    protected function show()
    {
        echo "Your Name : " . $this->name . "<br>";
    }
}
class Derived extends Base
{
    public function get()
    {
        echo "Your Name is : " . $this->name . "<br>";
    }
}
$test = new Derived("Yahoo Baba");
$test->name = "Baba Yahoo";
$test->get();

?>

Comments

Popular posts from this blog

Ajax Insert Records in Database Tutorial in PHP

SubQuery with EXISTS and NOT EXISTS in PHP

Submitting HTML Form data in JSON File (without MySql Database) in PHP