From:             
Operating system: WIN XP SP3+
PHP version:      5.3.2
Package:          Class/Object related
Bug Type:         Bug
Bug description:Access protected method violation

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 bug report at http://bugs.php.net/bug.php?id=52044&edit=1
-- 
Try a snapshot (PHP 5.2):            
http://bugs.php.net/fix.php?id=52044&r=trysnapshot52
Try a snapshot (PHP 5.3):            
http://bugs.php.net/fix.php?id=52044&r=trysnapshot53
Try a snapshot (trunk):              
http://bugs.php.net/fix.php?id=52044&r=trysnapshottrunk
Fixed in SVN:                        
http://bugs.php.net/fix.php?id=52044&r=fixed
Fixed in SVN and need be documented: 
http://bugs.php.net/fix.php?id=52044&r=needdocs
Fixed in release:                    
http://bugs.php.net/fix.php?id=52044&r=alreadyfixed
Need backtrace:                      
http://bugs.php.net/fix.php?id=52044&r=needtrace
Need Reproduce Script:               
http://bugs.php.net/fix.php?id=52044&r=needscript
Try newer version:                   
http://bugs.php.net/fix.php?id=52044&r=oldversion
Not developer issue:                 
http://bugs.php.net/fix.php?id=52044&r=support
Expected behavior:                   
http://bugs.php.net/fix.php?id=52044&r=notwrong
Not enough info:                     
http://bugs.php.net/fix.php?id=52044&r=notenoughinfo
Submitted twice:                     
http://bugs.php.net/fix.php?id=52044&r=submittedtwice
register_globals:                    
http://bugs.php.net/fix.php?id=52044&r=globals
PHP 4 support discontinued:          http://bugs.php.net/fix.php?id=52044&r=php4
Daylight Savings:                    http://bugs.php.net/fix.php?id=52044&r=dst
IIS Stability:                       
http://bugs.php.net/fix.php?id=52044&r=isapi
Install GNU Sed:                     
http://bugs.php.net/fix.php?id=52044&r=gnused
Floating point limitations:          
http://bugs.php.net/fix.php?id=52044&r=float
No Zend Extensions:                  
http://bugs.php.net/fix.php?id=52044&r=nozend
MySQL Configuration Error:           
http://bugs.php.net/fix.php?id=52044&r=mysqlcfg

Reply via email to