As the title states, PHP calls static methods directly using class names. There are two problems:
1 Will the constructor of the current class be called?
2 Will the constructor of the parent class of the current class be called?
欧阳克2017-07-07 10:36:10
You should test it yourself, the browser is the best teacher
Example 1:
<?php
class A{
function __construct(){echo"A::构造函数";}
static function myFun(){echo "你好,很高兴为你答题!";}
}
A::myFun();
?>
Example 2:
<?php
class A{
function __construct(){echo"A::构造函数";}
}
class B extends A{
static function myFun(){echo "你好,很高兴为你答题!";}
}
B::myFun();
?>
给我你的怀抱2017-07-07 10:36:10
1. No
2. No
The constructor is only called during instantiation. Static methods do not generate instances and will not call the constructor
伊谢尔伦2017-07-07 10:36:10
No, the constructor method will only be called when a class is instantiated. Static methods are stored in the static code area and are loaded as the class is loaded.