Calling a PHP Static Property through an Object Scope $Object::$ClassProperty

[I am using WAMP Server with PHP version 5.5.12]

Since I have started reading the PHP OOP Books I came to know that static properties or methods should be called like

ClassName::$Propertyname;

But today I tried this

$InitializedClass = new Class($args);
echo $InitializedClass::$ClassStaticProperty; //It Worked

Please let me understand what did my code do or what wrong I am doing. Any help is heartily appreciated by this learner.

<?php

class Human {
    public $name;
    static $title;

    public function __construct($name, $title) {
        $this->name = $name;
        self::$title = $title;
        }

    }

    class Animal extends Human {
        public $type;
        public function __construct($what){
            $this->type = $what;
            }
        }
$me = new Human('John', 'Deo');

    echo $me->name;
    echo $me::$title;

$dog = new Animal('Dog');

    echo $dog->type; 
    echo $dog::$title;
    echo Animal::$title;
    echo Human::$title;
    //Each code worked.
?>
链接地址: http://www.djcxy.com/p/58050.html

上一篇: Php继承,动态属性和新的static()构造函数

下一篇: 通过对象范围调用PHP静态属性$ Object :: $ ClassProperty