It's just a simple little experiment that contrasts the latency-bound and non-delayed efficiencies
Lazy binding is mostly the use of the static keyword to replace the original self, but the function is very powerful
Experiment Code:
Class A {protected static $CC 1 = Array (' A1 ', ' B ', ' C ', ' d ');p rotected static $CC 2 = Array (' A2 ', ' B ', ' C ', ' d ');p rotected s Tatic $CC 3 = Array (' A3 ', ' B ', ' C ', ' d ');p rotected static $CC 4 = array (' A4 ', ' B ', ' C ', ' d ');p rotected static $CC 5 = Array (' A5 ', ' B ', ' C ', ' d ');p ublic static function n1 () {return static:: $CC 1;} public static function N2 () {return static:: $CC 2;} public static function N3 () {return static:: $CC 3;} public static function N4 () {return static:: $CC 4;} public static function N5 () {return static:: $CC 5;}} Class C extends A {}class B {protected static $CC 1 = Array (' A1 ', ' B ', ' C ', ' d ');p rotected static $CC 2 = Array (' A2 ', ' B ', ' C ', ' d ');p rotected static $CC 3 = Array (' A3 ', ' B ', ' C ', ' d ');p rotected static $CC 4 = array (' A4 ', ' B ', ' C ', ' d ');p rotected s Tatic $CC 5 = array (' A5 ', ' B ', ' C ', ' d ');p ublic static function n1 () {return self:: $CC 1;} public static function N2 () {Return to self:: $CC 2;} public static function N3 () {Return to self:: $CC 3;} public static function N4 () {Return to self:: $CC 4;} Public Static function N5 () {return self:: $CC 5;}}
A total of a, B, C three classes, which are all static member variables and methods, where
The Class A uses a static delay,
Class B is non-delayed,
Class C is a deferred binding that inherits the Class A to implement static member variables and methods.
The process is not much to say, the environment is PHP5.4.27 directly on the test results:
There are two situations,
1. When there is only a, B class (That is, no class inherits from Class A), there is almost no difference in efficiency
2. When Class A is inherited by Class C, the class A performance using static delay binding will be slightly worse than Class B (as long as Class A has inherited classes will become slower)
Cycle 100,000 times, time-consuming between 2.8s ~ 3.2s gap in 0.3 seconds or so, it should still be negligible
Add a:
And then I added some test methods.
If the class C inherits the Class A, the static member variables in the Class A are overloaded, the more overloads are the faster and the class B (non-delay) is closer, but the class A is still slower than Class B and class C