#29689 [Asn->Csd]: default value of protected member overrides default value of private
| From: | stas@php.net | Date: | Thu, 09 Jun 2005 17:22:19 +0000 |
| Subject: | #29689 [Asn->Csd]: default value of protected member overrides default value of private | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-80099@lists.php.net to get a copy of this message | ||
ID: 29689
Updated by: stas@php.net
Reported By: php dot net at benjamin dot schulz dot name
-Status: Assigned
+Status: Closed
Bug Type: Zend Engine 2 problem
Operating System: *
PHP Version: 5CVS-2005-04-19
Assigned To: andi
New Comment:
This bug has been fixed in CVS.
Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
Thank you for the report, and for helping us make PHP better.
fixed it
Previous Comments:
------------------------------------------------------------------------
[2005-05-17 16:10:19] stas@php.net
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.
------------------------------------------------------------------------
[2005-04-19 16:19:11] sniper@php.net
<?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] tony2001@php.net
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
------------------------------------------------------------------------
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