#27367 [Opn->Bgs]: A protected parent constructor cannot be called
| From: | helly@php.net | Date: | Mon, 23 Feb 2004 17:21:11 +0000 |
| Subject: | #27367 [Opn->Bgs]: A protected parent constructor cannot be called | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-55382@lists.php.net to get a copy of this message | ||
ID: 27367
Updated by: helly@php.net
Reported By: andrey@php.net
-Status: Open
+Status: Bogus
Bug Type: Zend Engine 2 problem
Operating System: linux
PHP Version: 5CVS-2004-02-23 (dev)
New Comment:
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
protected or private constructors are callable from static members aka
factory pattern.
Previous Comments:
------------------------------------------------------------------------
[2004-02-23 12:12:32] andrey@php.net
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
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=27367&edit=1