php - Accessing static methods using newly created $obj or using class Name -


see class definition below:
i using 5.3.9 version of php

class a{     static function ab(){         echo "static function ab<br>";     }      public function xy(){         echo "public function xy<br>";     } }  $obj =  new a(); $obj->ab(); a::ab(); 

both functions call give same output without error

static function ab static function ab 

how possible static method can called class object? because static method calls using class name only?!

now difference between accessing these 2 ways call static method?

referring php.net website

declaring class properties or methods static makes them accessible without needing instantiation of class. property declared static can not accessed instantiated class object (though static method can).

a big difference is

because static methods callable without instance of object created, pseudo-variable $this not available inside method declared static.

refer page php.net/manual/en/language.oop5.static.php more details


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -