php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #20052 __construct() blocks use of __get() in parent
Submitted: 2002-10-23 17:20 UTC Modified: 2002-10-29 17:02 UTC
From: tater at potatoe dot com Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 4CVS-2002-10-23 OS: OS X 10.1
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: tater at potatoe dot com
New email:
PHP Version: OS:

 

 [2002-10-23 17:20 UTC] tater at potatoe dot com
If a child class has a __construct() function, it won't make
use of its parent's __get() function (and presumably other
overload functions too). Workaround: add a __get() to the child class and call parent::__get($property).

test code:

<?php
class a { function __get() { return 'a::_get'; } }
class b extends a { }
class c extends a { function __construct() { } }
class d extends a { function __construct() { } function __get($p) { return parent::__get($p); } }
$a = new a;
print "a->foo = {$a->foo}\n";
$b = new b;
print "b->foo = {$b->foo}\n";
$c = new c;
print "c->foo = {$c->foo}\n";
$d = new d;
print "d->foo = {$d->foo}\n";
?>

output:

PHP Notice:  Undefined property:  foo in /full/path/overload.php on line 11
overload.php(11) : Notice - Undefined property:  foo
a->foo = a::_get
b->foo = a::_get

Notice: Undefined property:  foo in /full/path/overload.php on line 11
c->foo =
d->foo = a::_get

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-10-29 17:02 UTC] sniper@php.net
Please do not submit the same bug more than once. An existing
bug report already describes this very problem. Even if you feel
that your issue is somewhat different, the resolution is likely
to be the same. Because of this, we hope you add your comments
to the original bug instead.

Thank you for your interest in PHP.


 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Jul 30 21:00:03 2025 UTC