php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #50302 final private function __construct
Submitted: 2009-11-25 22:24 UTC Modified: 2009-11-26 10:10 UTC
From: p dot reisinger at gmail dot com Assigned:
Status: Not a bug Package: Class/Object related
PHP Version: 5.3.1 OS:
Private report: No CVE-ID: None
 [2009-11-25 22:24 UTC] p dot reisinger at gmail dot com
Description:
------------
When somebody creates final private constructor then the class that extends this class cannot have constructor at all, even though private methods shouldn't be visible outside of the class. So final private constructor shouldn't allow calling parent::__construct(), but creating constructor should be allowed.
The same happens if class has final private method, then no subclass can use method with the same name (I know that there is no point creating private final, but it seems a problem when there'll be final instance variables in the future, plus it is a problem with constructors).

As I understand, parent's constructor is not called automatically, 
(parent::__construct() needs to be called) because if parent's constructor is private but not final then the code works.

Reproduce code:
---------------
class Test {
    final private function __construct() {}
}

class SubTest extends Test {
    // private methods shouldn't be visible
    // and I am not calling parent::__construct();
    public function __construct() {}
}


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-11-26 10:10 UTC] jani@php.net
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


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 16:01:29 2024 UTC