ID:               50892
 Updated by:       [email protected]
 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

Reply via email to