Static Members

 <?php

class Base
{
    public static $name = "Yahoo Baba";
    public static $name2 = "Hello World";

    public static function show()
    {
        echo self::$name ."<br>";
        echo self::$name2 . "<br>";
    }
    public function __construct($n)
    {
        self::show();
        self::$name = $n;
    }
}
class Derived extends Base
{
    public static function details()
    {
        echo parent::$name . "<br>";
        echo parent::$name2 . "<br>";
        parent::show();
    }
}
echo Base::$name . "<br>";
echo Base::$name2 . "<br>";
Base::show() . "<br>";

$test = new Base("Wow brother!");
$test->show();
echo "<br>";
$test->show();
echo "<br>";
Derived::details();

//  OUTPUT:
//Yahoo Baba
// Hello World
// Yahoo Baba
// Hello World
// Yahoo Baba
// Hello World
// Wow brother!
// Hello World

// Wow brother!
// Hello World

// Wow brother!
// Hello World
// Wow brother!
// Hello World
?>

Comments

Popular posts from this blog

Logical_Operators

SubQuery with EXISTS and NOT EXISTS in PHP

Get Functions