mune
V2EX  ›  PHP

请教在这里使用 static 和&具体有什么好处 static $redis; $redis || $redis = &Cache_Redis::instance();

  •  
  •   mune · Oct 27, 2017 · 2110 views
    This topic created in 3123 days ago, the information mentioned may be changed or developed.
    1 replies    2017-10-27 15:08:54 +08:00
    gouchaoer
        1
    gouchaoer  
       Oct 27, 2017
    用&没有任何好处,因为对象默认就是按引用传递,实际上 array 用&也没啥好处,因为 array 本来就做 COW 优化,除非你想改变传入参数 array 的值。。。
    至于 static 语法只是 singleton 模式而已,实际上 singleton 模式是一种反模式不值得鼓励的,因为很难测试。。。正确是用法是依赖注入
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3003 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 05:34 · PVG 13:34 · LAX 22:34 · JFK 01:34
    ♥ Do have faith in what you're doing.