ben548
V2EX  ›  PHP

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

  •  
  •   ben548 · Dec 28, 2015 · 2810 views
    This topic created in 3800 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   ·   Solana   ·   5542 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 46ms · UTC 05:53 · PVG 13:53 · LAX 22:53 · JFK 01:53
    ♥ Do have faith in what you're doing.