PHP Child class Magic __isset works but __get doesn’t

I have an abstract parent class Mongo_Document (from mongodb-php-odm) and an inherited class Model_ActionPlan. Mongo_Document has magic __isset and __get methods that interact with an array inside the Mongo_Document class.

I am trying to use the following code (snippet from inside a method of Model_ActionPlan):

if (isset($this->status))
    if (($this->status === "closed") AND ($this->close_type != "failure"))

(Note that close_type is guaranteed to be set if status == 'closed'.)

The isset call returns true and then execution proceeds to the next statement. There, I receive the following error:

 Undefined property: Model_ActionPlan::$status

However, if I replace $this->status with parent::__get('status'), this code works as expected. Note that everywhere else in the program, I am able to use:

$ap = new Model_ActionPlan($plan_id);
echo $ap->status;
// Prints 'closed' (or 'active') as expected

It is only here, inside the class itself, that this doesn’t work.

I looked around and I can’t seem to find anywhere that says that magic methods can’t be called in the child class. I could use the parent::__get call instead but I think that is probably the wrong way to do it. Does anyone know if there is a right/better way to do this?

Updated #1 2012-12-16:
The full code of the parent class is here on Github.

Updated #2 2012-12-18:
For the people who asked about where or whether it is set properly, the answer is that since calling parent::__get('status') does work, the problem is obviously not that the variable isn’t getting set. The __get() is getting its data from a private instace variable called _object. If I var_dump($this), I see that $this->_object['status'] does equal the expected “closed” value.

Update #3:
The code of the child class is available at
The important part starts on line 69.

I have seen this similar question but that one is about using a parent’s magic method to get the child’s properties and my issue is using the parent’s getter to get the parent’s properties.

Leave a Reply


Hire Me
Follow Me!
Most Popular Articles & Pages
Because your vote is Important
Sorry, there are no polls available at the moment.