php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #28430 Cannot extend built-in classes (mysqli)
Submitted: 2004-05-18 12:02 UTC Modified: 2004-06-05 20:34 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: bert at procurios dot nl Assigned: georg (profile)
Status: Closed Package: MySQL related
PHP Version: 5.0.0RC2 OS: *
Private report: No CVE-ID: None
 [2004-05-18 12:02 UTC] bert at procurios dot nl
Description:
------------
Extending the built-in class 'mysqli' doesn't give the expected and desired result. The extended class doesn't have the members the parent class has and is unusable.

We found a related mailinglist entry from more than a year ago: http://www.zend.com/lists/engine2/200302/msg00244.html

The possibility to extend built-in classes is a major feature in PHP5 - at least for us ;).

The reproduce code below is a minimal testcase - other more complicated tests failed as well.

Reproduce code:
---------------
class DB extends mysqli
{	
}

$DB1 = new DB('localhost', 'root', '', 'probase2');
$DB2 = new mysqli('localhost', 'root', '', 'probase2');

var_dump($DB1->thread_id);
var_dump($DB1->error);
var_dump($DB1->errno);

var_dump($DB2->thread_id);
var_dump($DB2->error);
var_dump($DB2->errno);

Expected result:
----------------
int(97)
string(0) ""
int(0)
int(98)
string(0) ""
int(0)

Actual result:
--------------
<br />
<b>Notice</b>:  Undefined property:  DB::$thread_id in <b>d:\htdocs_php5\ProBase2\TRUNK\probase\libsys\test.php</b> on line <b>10</b><br />
NULL
<br />
<b>Notice</b>:  Undefined property:  DB::$error in <b>d:\htdocs_php5\ProBase2\TRUNK\probase\libsys\test.php</b> on line <b>11</b><br />
NULL
<br />
<b>Notice</b>:  Undefined property:  DB::$errno in <b>d:\htdocs_php5\ProBase2\TRUNK\probase\libsys\test.php</b> on line <b>12</b><br />
NULL
int(97)
string(0) ""
int(0)


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-05-21 18:25 UTC] helly@php.net
some of the internal classas cannot be extended and unfortunatley they are not marked as 'final' right now. For you that means you need to extend it by a proxy class that reimplements the original class protocol and uses the original class as a property.
 [2004-05-21 18:31 UTC] helly@php.net
The classes in mysqli either need to be final or they need to be made extendable.
 [2004-06-05 20:34 UTC] georg@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 13:01:29 2024 UTC