|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2004-08-15 21:52 UTC] php dot net at benjamin dot schulz dot name
Description:
------------
protected member overrides private
Reproduce code:
---------------
<?php
class foo {
private $foo = 'foo';
function printFoo()
{
echo __CLASS__, ': ', $this->foo, '<br />';
}
}
class bar extends foo {
protected $foo = 'bar';
function printFoo()
{
parent::printFoo();
echo __CLASS__, ': ', $this->foo, '<br />';
}
}
class baz extends bar {
protected $foo = 'baz';
}
$bar = new bar;
$bar->printFoo();
echo '<hr />';
$baz = new baz();
$baz->printFoo();
?>
Expected result:
----------------
foo: foo
bar: bar
--
foo: foo
bar: baz
Actual result:
--------------
foo: foo
bar: bar
--
foo: baz
bar: baz
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 02:00:01 2025 UTC |
<?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?