|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2004-02-23 12:21 UTC] helly@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Nov 30 19:00:01 2025 UTC |
Description: ------------ By default if a constructor in a subclass is not defined the constructor of the parent class is being called (see example 1). However, if the parent constructor is declared "protected" and is visible to the child, the engine refuses to execute the constructor (Example 2 and result 2). Example 3 shows that the parent constructor is visible in the child when an explicit constructor is provided there. Reproduce code: --------------- Ex. 1: php -r 'class a { function a() {echo "const of a\n";}} class b extends a {} $a = new b();' Ex. 2: php -r 'class a { protected function a() {echo "const of a\n";}} class b extends a {} $a = new b();' Ex. 3: php -r 'class a { protected function a() {echo "const of a\n";}} class b extends a {public function b(){parent::a();}} $a = new b();' Expected result: ---------------- const of a const of a const of a Actual result: -------------- Result 1 : const of a Result 2 : PHP Fatal error: Call to protected a::a() from context '' in Command line code on line 1 Result 3 : const of a