php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #37632 Protected method access problem (similar bug 37212)
Submitted: 2006-05-29 18:43 UTC Modified: 2006-05-29 20:08 UTC
From: stochnagara at hotmail dot com Assigned: helly (profile)
Status: Closed Package: Class/Object related
PHP Version: 5CVS-2006-05-29 (snap) OS: *
Private report: No CVE-ID: None
 [2006-05-29 18:43 UTC] stochnagara at hotmail dot com
Description:
------------
In class structures where the sub-classes are extended non-linearly (i.e. multiple classes on the same tier), the sub-classes in different lines cannot access methods defined as protected in a shared parent class in eachother.

Actually this is a clone of bug 37212 but for method instead of variables.

Reproduce code:
---------------
class A {
	protected function testProtected() { echo "Test Protected Called in A"; }
}

class B extends A {
    public function doTest (A $obj) {
		$obj->testProtected();
    }
}

class C extends A {
	protected function testProtected() { echo "Test Protected Called in C"; }
}

$B = new B;
$C = new C;
$B->doTest ($C); // fatal

?>

Expected result:
----------------
Test Protected Called in C


Actual result:
--------------
Fatal error: Call to protected method C::testProtected() from context 'B' in c:\program files\apache group\Apache\htdocs\cinh.php on line 8


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-05-29 20:08 UTC] helly@php.net
Fixed in 5.2, HEAD. Since the rule cannot be fixed for properties in 5.1 it stays the same for methods in 5.1, too. That way we lower the WTF factor.
 [2006-05-29 20:08 UTC] helly@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 11:01:30 2024 UTC