因为对 java 的面向对象了解一些,在用 php 的面向对象时就认为 php 的 oop 和 java 的 oop 是一样的,但最近看别人的程序时,感觉 java 的 oop 在 php 中貌似有不少不一样,一头雾水。今天看 php manual ,有些明白了。。下面是摘自 php manual 中的。。
范围解析操作符(::)
范围解析操作符(也可称作 Paamayim Nekudotayim)或者更简单地说是一对冒号,可以用于访问静态成员、方法和常量,还可以用于覆盖类中的成员和方法。
当在类的外部访问这些静态成员、方法和常量时,必须使用类的名字。
Static Keyword
Declaring class members or methods as static makes them accessible without needing an instantiation of the class. A member declared as static can not be accessed with an instantiated class object (though a static method can).
For compatibility with PHP 4, if no visibility declaration is used, then the member or method will be treated as if it was declared as public.
Because static methods are callable without an instance of the object created, the pseudo variable $this is not available inside the method declared as static.
Static properties cannot be accessed through the object using the arrow operator ->.
Calling non-static methods statically generates an E_STRICT level warning.