I have below code
class MyClass
{
public static $count = 0;
public static function plusOne()
{
return "The count is " . ++self::$count . ".<br />";
}
}
$obj = new MyClass;
$obj->plusOne(); //Works proper for static function
echo '<br/>'.MyClass::$count; // count: 1
MyClass::plusOne(); //Works proper for static function
echo '<br/>'.MyClass::$count; // count: 2
----OUTPUT------
1
2
----------------
I have access static method by creating object (using ->) and by scope resolution operator (using ::) Method works properly But when I am trying to use static Property by scope resolution (using :: ) It display notice don't work. below is additional code.
$obj->count; // Notice: Undefined property: MyClass::$count
I have access static method by creating object (using ->) and by scope resolution operator (using ::) BUT still static properties count increases WHY?
Why Different access rule for static property (only :: ) and method (by ->, ::)?