#29689 [Fbk->Opn]: default value of protected member overrides default value of private

From: Date: Tue, 31 Aug 2004 17:00:42 +0000
Subject: #29689 [Fbk->Opn]: default value of protected member overrides default value of private
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-65531@lists.php.net to get a copy of this message
 ID:               29689
 User updated by:  php dot net at benjamin dot schulz dot name
 Reported By:      php dot net at benjamin dot schulz dot name
-Status:           Feedback
+Status:           Open
 Bug Type:         Unknown/Other Function
 Operating System: linux
 PHP Version:      5.0.1
 New Comment:

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


Previous Comments:
------------------------------------------------------------------------

[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

------------------------------------------------------------------------

[2004-08-31 16:24:10] tony2001@php.net

Private members belong only to the class where they were defined and
cannot be inherited.

------------------------------------------------------------------------

[2004-08-15 22:03:50] php dot net at benjamin dot schulz dot name

default value of protected member overrides default value of private

------------------------------------------------------------------------

[2004-08-15 21:52:17] 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


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=29689&edit=1


Thread (9 messages)

« previous php.bugs (#65531) next »