#50892 [Opn->Bgs]: Protected members of non-congruent children classes are visible
| From: | jani@php.net | Date: | Mon, 01 Feb 2010 09:32:01 +0000 |
| Subject: | #50892 [Opn->Bgs]: Protected members of non-congruent children classes are visible | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-147077@lists.php.net to get a copy of this message | ||
ID: 50892
Updated by: jani@php.net
Reported By: EdwardDrapkin at gmail dot com
-Status: Open
+Status: Bogus
Bug Type: Class/Object related
Operating System: Irrelevant
PHP Version: 5.3.1
New Comment:
RTFM:
"Members declared protected can be accessed only within the class
itself and by inherited and parent classes."
http://php.net/manual/en/language.oop5.visibility.php
Previous Comments:
------------------------------------------------------------------------
[2010-01-31 20:21:11] EdwardDrapkin at gmail dot com
Description:
------------
When you have two classes that extend the same base class, if the
protected members are declared in the base class, they are visible to
each other. Because the class variables are protected, they should not
be available to other classes, even if they share the same parent (but
are of different types themselves)!
Reproduce code:
---------------
<?php
class foo {
public $public = "a";
private $private = "b";
protected $protected = "protected";
}
class bar extends foo {
}
class kid extends foo {
public function test() {
$b = new bar();
var_dump(get_object_vars($b));
var_dump($b->protected);
}
}
$k = new kid();
$k->test();
Expected result:
----------------
array(1) {
["public"]=>
string(1) "a"
}
Visibility error.
Actual result:
--------------
array(2) {
["public"]=>
string(1) "a"
["protected"]=>
string(9) "protected"
}
string(9) "protected"
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=50892&edit=1