php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #45097 Magic __get() can't access inherited properties
Submitted: 2008-05-26 18:54 UTC Modified: 2008-05-30 11:58 UTC
From: ndaugherty987 at gmail dot com Assigned:
Status: Not a bug Package: Class/Object related
PHP Version: 5.2.6 OS: linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: ndaugherty987 at gmail dot com
New email:
PHP Version: OS:

 

 [2008-05-26 18:54 UTC] ndaugherty987 at gmail dot com
Description:
------------
The magic overloading function __get() can't seem to access inherited, non-visible properties. If you overload with __get() in a base class, then extend that class, the base class's __get() will return NULL when accessing an inaccessible property of the child class. The __get() function doesn't even see the property as being set (if you run an isset($name) in the __get() call, it returns false.

Reproduce code:
---------------
class testParent {
	function __get($name){
		return $this->$name;
	}
}

class testChild extends testParent {
	private $testVar = 'Bar';
}

$t = new testChild;

echo 'Foo: ' . $t->testVar;

Expected result:
----------------
You would expect the code to output 'Foo: Bar'. instead, it outputs 'Foo:', because the __get() in testParent apparently can't see the private vars in testChild.

Actual result:
--------------
Output's 'Foo:', withOUT the 'Bar'

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-05-30 11:58 UTC] felipe@php.net
This is expected, use protected/public visibility.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Jul 30 05:00:03 2025 UTC