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

 ID:               52120
 Updated by:       vr...@php.net
 Reported by:      vr...@php.net
 Summary:          Unable to call inherited protected __construct
-Status:           Feedback
+Status:           Open
 Type:             Bug
 Package:          Scripting Engine problem
 Operating System: *
 PHP Version:      5.3.2

 New Comment:

<?php

class A {

        protected function f() {

        }

}



class B extends A {

        static function test() {

                $c = new C;

                $c->f();

        }

}



class C extends A {

        protected function f() {

                echo "OK\n";

        }

}



B::test();

?>



This should output OK which it really does.


Previous Comments:
------------------------------------------------------------------------
[2010-06-20 00:39:10] fel...@php.net

"This is true for all methods except __construct()."

Can you provide an test case for non __construct method? I cannot
reproduce it.

------------------------------------------------------------------------
[2010-06-18 17:15:42] vr...@php.net

Description:
------------
Protected visibility allows accessing parent members and also members of
parent's children. If class A defines protected method f() and classes B
and C are children of A then B can call C::f(). This is true for all
methods except __construct().

Test script:
---------------
class A {

        protected function __construct() {

        }

}



class B extends A {

        static function test() {

                new C;

        }

}



class C extends A {

        protected function __construct() {

                echo "OK\n";

        }

}



B::test();



Expected result:
----------------
OK

Actual result:
--------------
Fatal error: Call to protected C::__construct() from context 'B' on line
9


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



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

Reply via email to