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

 ID:               52044
 Updated by:       degeb...@php.net
 Reported by:      public at proside dot fr
 Summary:          Access protected method violation
-Status:           Open
+Status:           Bogus
 Type:             Bug
 Package:          Class/Object related
 Operating System: WIN XP SP3+
 PHP Version:      5.3.2

 New Comment:

Yes, you are wrong. One MyParent object knows the private/protected
interface of all other MyParent objects, so it is allowed to access it.
Other classes don't, so they're not allowed.



Thanks for your interest though.


Previous Comments:
------------------------------------------------------------------------
[2010-06-11 10:20:25] public at proside dot fr

Description:
------------
In one case, the PHP engine allows access to the protected methods of an
instanciated class



As the documentation says : protected methods are only available inside
the class that declares it and inside the tree of derivated classes. If
you look at the code, we are in none of these case : $a is a standalone
instance of MyParent so the protected methods of class MyParent should
be hidden.



Am i wrong ?

Test script:
---------------
<?php

class MyParent {        

   protected function getProtectedParent() { return 'Parent_Protected';
}

}



class MyChild extends MyParent {

   function getPublicChild() {

      # --> new standalone instance of MyParent

      $a = new MyParent();

      # --> here it's possible to access to the protected method of $a
!

      return $a->getProtectedParent();

   }

}



$cls = new MyChild();

$test = $cls->getPublicChild();

Expected result:
----------------
Fatal error : access level violation

Actual result:
--------------
$test = 'Parent_Protected'


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



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

Reply via email to