|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #44784 "Undefined property" notice when accessing property in __get and __set
Submitted: 2008-04-20 01:17 UTC Modified: 2008-04-20 10:53 UTC
From: marvinpaul at mapkreke dot com Assigned:
Status: Not a bug Package: Class/Object related
PHP Version: 5.2.5 OS: Windows Vista
Private report: No CVE-ID: None
 [2008-04-20 01:17 UTC] marvinpaul at mapkreke dot com
If you have a child class that inherits from a parent class that implements __get and __set and you access a private property from within these functions, then you will get a notice "Undefined property" when trying to access this property from an instance of the child class. If you try accessing the properties from an instance of the parent class, it works as expected.

Reproduce code:
class ParentClass
    private $parentMessage = "Hello, from parent!";

    private function __get($property)
        echo "__get($$property)\n";

        return $this->$property;
    private function __set($property, $value)
        echo "__set($$property, $value)\n";

        $this->$property = $value;

class ChildClass extends ParentClass
    private $childMessage = "Hello, from child!";

$parent = new ParentClass();
echo $parent->parentMessage . "\n";

$child = new ChildClass();
echo $child->childMessage . "\n";

Expected result:
Hello, from parent!
Hello, from child!

Actual result:
Hello, from parent!
Notice:  Undefined property:  ChildClass::$childMessage in C:\www\bug.php on line 11


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2008-04-20 10:53 UTC]
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit as this bug system is not the
appropriate forum for asking support questions.  Due to the volume
of reports we can not explain in detail here why your report is not
a bug.  The support channels will be able to provide an explanation
for you.

Thank you for your interest in PHP.

That's expected, from the context of ParentClass::__get, any private property of the child class won't be accessible.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Feb 21 16:01:28 2024 UTC