static method:
Example
Class A{public static function A () {# code ...} public static function B () {# code ...}} Use A::a (); A::b ();
When the script is interpreted, the static method is loaded into memory (and a single copy of the storage). Use it as if you were using a function.
Single Example:
In order to achieve a class in memory only a single copy is stored, with static variables through code implementation of a design pattern
Example
Class Container () {protected Static $loadedSingletonClasses = [];p ublic static function loadsingletonclass ($className = ' ') {if (!isset (self:: $loadSingletonClass [$className])) {self:: $loadSingletonClass [$className] = new $className;} Return self:: $loadSingletonClass [$className];}} $a = Container::loadsingletonclass ("Foo\bar\myclass"); $b = Container::loadsingletonclass ("Foo\bar\myclass");
In the above code $a the $b variable points to the same memory address, (but if you want to trigger both variables to instantiate the class's destructor needs to destroy both variables, see PHP Object-oriented knowledge summary)
One thing that differs from static methods is that static methods are loaded into memory when the script is interpreted, and the singleton is loaded into memory only when new is available (provided the code for both is loaded into the memory code area)
Auto Load:
There is an explanation of the automatic loading in front (AutoLoad implementation Mechanism in PHP)
When we
Instantiate class new Class
Call static method Class::func ()
Inheriting classes, interfaces subclass extends parentclass{}
This will trigger the auto-load function:
When we alias a class, the class name passed is also the class before the alias.
The above describes the PHP object-oriented single and static methods of comparison, and about class automatic loading analysis, including the aspects of the content, more relevant content please pay attention to topic.alibabacloud.com (www.php.cn)!