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

[我正在使用PHP版本5.5.12的WAMP Server]

自从我开始阅读PHP OOP书籍后,我开始知道静态属性或方法应该被称为类似

ClassName::$Propertyname;

但今天我试了这个

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

请让我明白我的代码做了什么或者我做了什么错误。 这位学习者衷心感谢任何帮助。

<?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/58049.html

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

下一篇: Why in late static binding child class gets data from parent and current methods