Bug #52120 [Opn]: Unable to call inherited protected __construct
Edit report at http://bugs.php.net/bug.php?id=52120&edit=1
ID: 52120
Updated by: felipe@php.net
Reported by: vrana@php.net
Summary: Unable to call inherited protected __construct
Status: Open
Type: Bug
Package: Scripting Engine problem
Operating System: *
PHP Version: 5.3.2
New Comment:
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.
Previous Comments:
------------------------------------------------------------------------
[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 http://bugs.php.net/bug.php?id=52120&edit=1
Thread (5 messages)