php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #33806 Access to protected functions from static function in base class
Submitted: 2005-07-21 15:25 UTC Modified: 2005-07-21 15:54 UTC
From: pascal dot parietti at fh-aargau dot ch Assigned:
Status: Not a bug Package: Class/Object related
PHP Version: 5.0.4 OS: Linux, 2.6.11
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: pascal dot parietti at fh-aargau dot ch
New email:
PHP Version: OS:

 

 [2005-07-21 15:25 UTC] pascal dot parietti at fh-aargau dot ch
Description:
------------
A static function in the base class (A) can execute a protected function in a derived class (B).

If the same function is called from outside of class A the PHP Fatal error occurs as excepted.

The error also occurs with the CVS Snapshot php5-STABLE-200507211237 compiled with ./configure && make

Reproduce code:
---------------
<?php
class A {
        public static function test()   {
                $a = new B();
                $a->test2(); # why does this work?
        }
}
class B extends A {
        protected function test2()      {
                echo "B: test2 \n";
        }
}

A::test();

$b = new B();

# call a protected function -> PHP Fatal error as excepted:
$b->test2(); 
?>


Expected result:
----------------
PHP Fatal error:  Call to protected method B::test2() on line  5


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-07-21 15:32 UTC] tony2001@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


 [2005-07-21 15:54 UTC] pascal dot parietti at fh-aargau dot ch
As in the manual is written:

'...Protected limits access to inherited classes (and to the class that defines the item)...' 

I assume that it is not possible to access this protected function from outside the class or inherited classes?
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Jul 24 10:01:28 2024 UTC