#44141 [Opn]: private parent constructor callable through static function
| From: | felipe@php.net | Date: | Sun, 17 Feb 2008 15:12:55 +0000 |
| Subject: | #44141 [Opn]: private parent constructor callable through static function | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-122363@lists.php.net to get a copy of this message | ||
ID: 44141
Updated by: felipe@php.net
Reported By: B dot Steinbrink at gmx dot de
Status: Open
Bug Type: Class/Object related
Operating System: Debian Linux
PHP Version: 5.2.5
New Comment:
I think that the parent ctor/dtor private shouldn't be called. Hence,
here's a patch (5_3):
http://felipe.ath.cx/diff/bug44141.diff
It doesn't issue error message, only isn't inherited.
Previous Comments:
------------------------------------------------------------------------
[2008-02-17 06:09:31] B dot Steinbrink at gmx dot de
Description:
------------
A class that is derived from a class with a private constructor and
which does not provide its own constructor, can call the private parent
constructor through a static function.
Reproduce code:
---------------
<?php
class X
{
public $x;
private function __construct($x)
{
$this->x = $x;
}
}
class Y extends X
{
static public function cheat($x)
{
return new Y($x);
}
}
$y = Y::cheat(5);
echo $y->x, PHP_EOL;
Expected result:
----------------
Fatal error: Call to private X::__construct() from invalid context ...
Actual result:
--------------
5
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=44141&edit=1