Ejemplo n.º 1
0
<?php

$object = new Subscriber();
$object->name = "Fred";
$object->password = "******";
$object->phone = "012 345 6789";
$object->email = "*****@*****.**";
$object->display();
class User
{
    public $name, $password;
    function save_user()
    {
        echo "Save User code goes here";
    }
}
class Subscriber extends User
{
    public $phone, $email;
    function display()
    {
        echo "Name:  " . $this->name . "<br>";
        echo "Pass:  "******"<br>";
        echo "Phone: " . $this->phone . "<br>";
        echo "Email: " . $this->email;
    }
}
Ejemplo n.º 2
0
echo "Test B: " . $temp->get_sp() . "<br/>";
echo "Test C: " . $temp->static_property . "<br/>";
class Test
{
    static $static_property = "I am static";
    function get_sp()
    {
        return self::$static_property;
    }
}
$object1 = new Subscriber();
$object1->name = "Kelvin";
$object1->password = "******";
$object1->phone = "010 203902929";
$object1->email = "*****@*****.**";
$object1->display();
class User1
{
    public $name, $password;
    function save_user()
    {
        echo "Save User code goes here.";
    }
}
class Subscriber extends User
{
    public $phone, $email;
    function display()
    {
        echo "Name : " . $this->name . "<br/>";
        echo "Pass : "******"<br/>";
Ejemplo n.º 3
0
    function __construct($name_, $pass_, $phone_, $email_)
    {
        User::__construct($name_, $pass_);
        // call parent constructor
        // We will not default call it
        $this->phone = $phone_;
        $this->email = $email_;
    }
    function display()
    {
        User::save_user();
        // call function in parent class.
        // we can also do Subscriber::function_name();
        echo "Name: " . $this->name . "<br>";
        echo "Password: {$this->password} <br>";
        echo "Phone: {$this->phone} <br>";
        echo "Email: {$this->email} <br>";
    }
    final function copyright()
    {
        // final means cannot be changed for its subclass.
        echo "Copyright: This class could not be changed for its subclasses! <br>";
    }
}
$sub = new Subscriber("Beibin1", "pass1", 9017343790, "*****@*****.**");
$sub->display();
$sub->copyright();
?>
	</body>
</html>