Bug #52120 [Opn->Ver]: Unable to call inherited protected __construct
| From: | nikic@php.net | Date: | Thu, 15 Aug 2019 13:45:59 +0000 |
| Subject: | Bug #52120 [Opn->Ver]: Unable to call inherited protected __construct | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-222260@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=52120&edit=1
ID: 52120
Updated by: nikic@php.net
Reported by: vrana@php.net
Summary: Unable to call inherited protected __construct
-Status: Open
+Status: Verified
Type: Bug
Package: Scripting Engine problem
Operating System: *
PHP Version: 5.3.2
Block user comment: N
Private report: N
Previous Comments:
------------------------------------------------------------------------
[2010-07-03 18:31:39] felipe@php.net
There was an issue related to this question times ago. See bug #37632
Which has a test (Zend/tests/bug37632.phpt) checking exactly what you are reporting as a bug. The
fix for this issue is simple, but I don't know really if this is the expected behavior or not.
------------------------------------------------------------------------
[2010-06-21 14:21:17] vrana@php.net
<?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.
------------------------------------------------------------------------
[2010-06-20 00:39:10] felipe@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] vrana@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 https://bugs.php.net/bug.php?id=52120&edit=1