ben548
V2EX  ›  PHP

$this->values[$id]($this),这种写法是什么意思呢?

  •  
  •   ben548 · Dec 28, 2015 · 3097 views
    This topic created in 3942 days ago, the information mentioned may be changed or developed.

    在看 php 的依赖注入框架 pimple 的源码时,看到这样的代码,感觉很奇怪,这种写法是什么意思呢?对了,$this->values 是一个数组

    2 replies  •  2015-12-28 18:35:18 +08:00
    cxbig
        1
    cxbig  
       Dec 28, 2015
    数组里都是 fn , key 可以匹配就直接调用。
    这么写太短,除非提前验证$id 有对应的 fn 。
    个人不推荐这种写法。在类里用标准的反射 method 调用比较好。
    ben548
        2
    ben548  
    OP
       Dec 28, 2015
    @cxbig 明白了,谢谢
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   933 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 20:54 · PVG 04:54 · LAX 13:54 · JFK 16:54
    ♥ Do have faith in what you're doing.