doucuodan0897 2014-10-07 12:29
浏览 65

从父类获取属性调用

I have the following code:

class Page extends APage{

    /**
     * @findby selector
     */
    protected $property

    public function getPropertyCount(){
        count($this->property);
    }

}


class APage{

    protected function initPropertyByAnnotation(){

    }      

}

Im using selenium with php, In selenium you select an element with a selector. I want the parent class to detect a call to the childs property so i can handle the actual selecting.

I thought that this was possible through the __get magic method, but it turns out its only triggered when a property is not defined.

Is there a way to detect the call some way without using a helper method like getProperty?

  • 写回答

1条回答 默认 最新

  • dongzhao4036 2014-12-19 12:21
    关注

    You can use the __get() function changing the scope of your property to private.
    As the docs says:

    __get() is utilized for reading data from inaccessible properties.

    public function __get($field) {
        if ($field == 'property') { //the name of your property
            //do something that you want
        }
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统