ID: 29689 Updated by: [EMAIL PROTECTED] Reported By: php dot net at benjamin dot schulz dot name Status: Assigned Bug Type: Zend Engine 2 problem Operating System: * PHP Version: 5CVS-2005-04-19 Assigned To: andi New Comment:
No, I think it should output foo, baz, baz. Private property is to behave for external functions as if it did not exist at all. However, protected property is shared by the whole inheritance chain, so redefining it means redefining it everywhere. Previous Comments: ------------------------------------------------------------------------ [2005-04-19 16:19:11] [EMAIL PROTECTED] <?php class foo { private $foo = 'foo'; function printFoo1() { echo __CLASS__, ': ', $this->foo, "\n"; } } class bar extends foo { protected $foo = 'bar'; function printFoo2() { echo __CLASS__, ': ', $this->foo, "\n"; } } class baz extends bar { protected $foo = 'baz'; function printFoo3() { echo __CLASS__, ': ', $this->foo, "\n"; } } $bar = new baz; $bar->printFoo1(); $bar->printFoo2(); $bar->printFoo3(); ?> Outputs: foo: baz bar: baz baz: baz When it should output: foo: foo bar: bar baz: baz Right? ------------------------------------------------------------------------ [2004-08-31 19:00:41] php dot net at benjamin dot schulz dot name you don't get the point, the problem is that baz's protected $foo overrides foo's private $foo, that should not happen using parent::foo() is a common technique, and there is a $this because it get's the context of the calling point ------------------------------------------------------------------------ [2004-08-31 18:32:35] [EMAIL PROTECTED] Please, be more verbose next time if you want to get any help. Your conciseness doesn't help very much. The problem is that you're trying to access class members through $this variable using static methods. As you can understand in this case there is no $this and behavior seems to be undefined (shouldn't there be an error, btw?). ------------------------------------------------------------------------ [2004-08-31 17:48:56] php dot net at benjamin dot schulz dot name yep tony, you're right, and now read the bug report ------------------------------------------------------------------------ [2004-08-31 16:24:10] [EMAIL PROTECTED] Private members belong only to the class where they were defined and cannot be inherited. ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at http://bugs.php.net/29689 -- Edit this bug report at http://bugs.php.net/?id=29689&edit=1