" but are accessible with "::"? Here is the documentation from the static keyword of PHP.net: A pr...">

Why are static properties unavailable with "->" but are accessible with "::"?

Here is the documentation from the static keyword of PHP.net:

A property declared as static cannot be accessed using an instance of a class object (although a static method can be used).

So why does the following code work?

Here is their sample code (I abbreviated it):

 <?php class Foo { public static $my_static = 'foo'; } $foo= new Foo(); print $foo::$my_static; //print 'foo' ?> 

Why $foo::$my_static still work here? Thanks everyone!

+5
source share
1 answer

A :: ( T_PAAMAYIM_NEKUDOTAYIM ) for this purpose is called the region resolution operator. It allows access to the static property of an object.

+1
source

Source: https://habr.com/ru/post/1243957/


All Articles