|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #44141 private parent constructor callable through static function
Submitted: 2008-02-17 06:09 UTC Modified: 2008-02-21 13:57 UTC
From: B dot Steinbrink at gmx dot de Assigned: dmitry
Status: Closed Package: Class/Object related
PHP Version: 5.2.5 OS: Debian Linux
Private report: No CVE-ID:
 [2008-02-17 06:09 UTC] B dot Steinbrink at gmx dot de
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:
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:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2008-02-17 15:12 UTC]
I think that the parent ctor/dtor private shouldn't be called. Hence, here's a patch (5_3):

It doesn't issue error message, only isn't inherited.
 [2008-02-21 13:57 UTC]
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
Thank you for the report, and for helping us make PHP better.

PHP Copyright © 2001-2015 The PHP Group
All rights reserved.
Last updated: Tue Dec 01 16:01:38 2015 UTC