php - Get property call from parent class

51

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?

691

Answer

Solution:

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
    }
}

People are also looking for solutions to the problem: Wordpress hook to add content under title or post status buttons on edit.php

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.