|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2010-06-18 17:15 UTC] 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
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Nov 17 20:00:01 2025 UTC |
<?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.