php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #29780 Constructor isn't called if a class is extended from a built in class
Submitted: 2004-08-21 11:58 UTC Modified: 2005-10-02 22:48 UTC
From: d dot khan at ventigo dot com Assigned:
Status: Closed Package: PDO related
PHP Version: 5.* OS: *
Private report: No CVE-ID: None
 [2004-08-21 11:58 UTC] d dot khan at ventigo dot com
Description:
------------
Hello,

maybe this is bogus but I found a situation where the OOP engine doesn't behave as - at least I - would expect.

I tried to extend the PDO extension and my local construct method isn't called.
The engine always calls the parent construct method.

Greetings

Daniel Khan

Reproduce code:
---------------
Class rltxPDO extends PDO {

    function __construct() {
        echo 'Called in child';
    }

    public static function instance() {
        static $instance;
        if (!$instance) {
            $instance = new rltxPDO();
        }
        return $instance;
    }
}

Expected result:
----------------
Output: Called in child

Actual result:
--------------
Warning: PDO::__construct() expects at least 1 parameter, 0 given

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-08-23 18:20 UTC] tony2001@php.net
This code:
<?
class test extends stdClass {

    function __construct() {
        echo 'Called in child';
    }

}

$test = new test;
?>
works fine and outputs 'Called in child' for me.
Please, check it one more time and/or try newer snapshot.
 [2004-08-25 22:46 UTC] d dot khan at ventigo dot com
You example works - mine doesn't. It seems to be an oddity with extensions...

Example code:
<?php
class test extends stdClass {

    function __construct() {
        echo 'Called in child';
    }

}
$test = new test;


Class rltxPDO extends PDO {

    function __construct() {
        echo 'Called in child 2';
    }
}

$test2 = new rltxPDO;
?>

Output:
Called in child
Warning: PDO::__construct() expects at least 1 parameter, 0 given in /home/shares/development/khan/wandern/html/test.php on line 19
 [2004-08-26 20:32 UTC] helly@php.net
HINT to all extension developers:

Constructors of internal classes need to have the name '__construct' rather that the class's name.
 [2004-08-29 08:10 UTC] tony2001@php.net
Works fine for me with latest PHP and PDO.
Btw, this is not ZE problem, reclassifying.
 [2004-09-01 18:00 UTC] d dot khan at ventigo dot com
weird.

PHP Version 5.0.1

PDO:
Version         0.1.1
Release Date    2004-05-21

PDO_MYSQL:
Version         0.1
Release Date    2004-05-18

Spits out that error.
 [2005-01-24 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 [2005-10-02 22:48 UTC] helly@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: Fri Dec 06 01:01:29 2024 UTC