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
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: pmiroslawski at gmail dot com
New email:
PHP Version: OS:

 

 [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

Pull Requests

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: Thu Nov 21 15:01:30 2024 UTC