相關(guān)關(guān)鍵詞
關(guān)于我們
最新文章
PHP靜態(tài)延遲綁定和普通靜態(tài)效率的對比
PHP靜態(tài)延遲綁定和普通靜態(tài)效率的對比
只是一個簡單的小實驗,對比了下 延遲綁定 和 非延遲的效率
延遲綁定主要就是使用 static 關(guān)鍵字來替代原來的 self ,但功能非常強大了
實驗代碼:
class A { protected static $cc1 = array('a1', 'b', 'c', 'd'); protected static $cc2 = array('a2', 'b', 'c', 'd'); protected static $cc3 = array('a3', 'b', 'c', 'd'); protected static $cc4 = array('a4', 'b', 'c', 'd'); protected static $cc5 = array('a5', 'b', 'c', 'd'); public static function n1() { return static::$cc1; } public static function n2() { return static::$cc2; } public static function n3() { return static::$cc3; } public static function n4() { return static::$cc4; } public static function n5() { return static::$cc5; } } class C extends A { } class B { protected static $cc1 = array('a1', 'b', 'c', 'd'); protected static $cc2 = array('a2', 'b', 'c', 'd'); protected static $cc3 = array('a3', 'b', 'c', 'd'); protected static $cc4 = array('a4', 'b', 'c', 'd'); protected static $cc5 = array('a5', 'b', 'c', 'd'); public static function n1() { return self::$cc1; } public static function n2() { return self::$cc2; } public static function n3() { return self::$cc3; } public static function n4() { return self::$cc4; } public static function n5() { return self::$cc5; } }