php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #38003 singleton and inheritance
Submitted: 2006-07-04 12:22 UTC Modified: 2006-07-05 11:49 UTC
From: pmiroslawski at gmail dot com Assigned: tony2001 (profile)
Status: Closed Package: Class/Object related
PHP Version: 5.1.4 OS: Linux DEBIAN 3.1
Private report: No CVE-ID: None
 [2006-07-04 12:22 UTC] pmiroslawski at gmail dot com
Description:
------------
Problem with create of object class then contruct is private. I use singleton pattern and inheritance and I can create object (no error and warning) if i didn't use inheritance was error (this behavior is ok).

Reproduce code:
---------------
<?php
class DB extends mysqli{
    private static $instance;
    
    private function __construct($hostname=DB_HOST, $username=DB_USER, $password=DB_PASSWORD, $database=DB_DATABASE){        
        //parent::__construct($hostname, $username, $password, $database);
    }
    
    public static function getInstance() {
        if (!isset(self::$instance)) {
            self::$instance = new DB();
        } 
        return self::$instance;
    }
}

$DB = new DB();
?>

Expected result:
----------------
Fatal error: Call to private DB::__construct() 

Actual result:
--------------
Everything is ok. No error! No warning!

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-07-05 11:49 UTC] tony2001@php.net
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
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 08:01:29 2024 UTC