News新闻

业界新闻动态、技术前沿
Who are we?

您的位置:首页      乐道系统FAQ      PHP静态延迟绑定和普通静态效率的对比

PHP静态延迟绑定和普通静态效率的对比

发布日期:2017-10-20 00:00:00 101

PHP静态延迟绑定和普通静态效率的对比

只是一个简单的小实验,对比了下 延迟绑定 和 非延迟的效率

延迟绑定主要就是使用 static 关键字来替代原来的 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; 
  } 
}