Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
嗨,有人知道如何从 PHP 类的实例访问该类的公共静态数据成员吗?
例如通过
<?php class Foo { public function bar() { echo '-> '. self::$data . ' <-'; } public static $data = 'FooData'; } $foo = new Foo; $foo->bar();
另见: http: //php.net/language.oop5.late-static-bindings
我不了解 PHP,但您不能从它的实例访问类的静态成员。静态成员是每个类型一个而不是每个实例一个。