Accessing static property %s::$%s as non static¶
Description¶
The property
property is declared as static, and should be access with the ::
operator.
Accessing that property with the ->
or ?->
object operators is quite safe, as there is no confusion with the name of the property, and the object holds the name of the host class.
On the other hand, using the object operators does not provide accurate information about the actual property.
Example¶
<?php
class X {
public static $property = 1;
}
$x = new X;
echo $x->property;
?>
Literal Examples¶
Accessing static property X::$property as non static
Solutions¶
Use the
::
operator to access static properties.Drop the
static
option on the property.