php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #43083 Protected method access from outside class.
Submitted: 2007-10-23 14:22 UTC Modified: 2007-10-23 16:09 UTC
From: purpurby at gmail dot com Assigned:
Status: Not a bug Package: Class/Object related
PHP Version: 5.2.4 OS: RedHat
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: purpurby at gmail dot com
New email:
PHP Version: OS:

 

 [2007-10-23 14:22 UTC] purpurby at gmail dot com
Description:
------------
Availability to call protected method from outside class or its descendants.

Reproduce code:
---------------
<?php

class a
{
  protected function aa()
  {
    echo "a-aa\n";
  }
}

class b extends a
{
  protected function aa()
  {
    echo "b-aa\n";
  }  
}

// Extends is affects on the behaviour:
//   - When "c" extends the "a" - not correct behaviour: working as in "Actual result"
//   - When "c" NOT extends the "a" - correct behaviour: working as in "Expected result"
class c extends a 
{
  public function cc()
  {
    $obj = new a();
    $obj->aa();
    
    $obj2 = new b();
    $obj2->aa();
  }

}

$c = new c();
$c->cc();

?>

Expected result:
----------------
Fatal error: Call to protected method a::aa() from context 'c'

Actual result:
--------------
a-aa
b-aa

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-10-23 16:09 UTC] helly@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

First part is perfectly right. As binding happens at compile time only relevant part is that C is-a A, hence inside C calls to A\'s protected members are fine. The other thing is a bit odd since technically C and B are different things. However what you call is inside A and both have A as a common root, hence that is fine as well.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 13:01:28 2024 UTC