From: jax at student dot unibe dot ch
Operating system: Gentoo Linux
PHP version: 5.1.2
PHP Bug Type: MySQLi related
Bug description: mysqli->fetch_object cripples mysqli object so that it can't
be closed correctl
Description:
------------
Test Case for mysqli->fetch_object bug
class A and class B contain the exact same code
Using mysqli->fetch_object causes warning when the destructor of B is
called (mysqli->close()):
Warning: mysqli::close() [function.close]: Couldn't fetch mysqli in
/home/path/to/php/test.php on line 56 (destructor of B)
If mysqli->fetch_assoc is used instead of fetch_object, it works fine.
Replace
$row = $result->fetch_object();
echo $row->my_time;
With
$row = $result->fetch_assoc();
echo $row['my_time'];
to test
something must be wrong with fetch_object
Reproduce code:
---------------
class A {
private $mysqli;
public function __construct() {
$this->mysqli = new mysqli("localhost", "u", "p", "test");
$result = $this->mysqli->query("SELECT NOW() AS my_time");
// -------- Line Causing Problem ------
$row = $result->fetch_object();
echo $row->my_time."<br>";
$result->close();
}
public function __destruct() {
$this->mysqli->close();
}
}
class B {
private $mysqli;
public function __construct() {
$this->mysqli = new mysqli("localhost", "u", "p", "test");
$result = $this->mysqli->query("SELECT NOW() AS my_time");
// -------- Line Causing Problem --------
$row = $result->fetch_object();
echo $row->my_time."<br>";
$result->close();
}
public function __destruct() {
$this->mysqli->close();
}
}
$A = new A();
$B = new B();
Expected result:
----------------
$this->mysqli->close() should work without throwing an error
Actual result:
--------------
2006-04-02 15:01:36
2006-04-02 15:01:36
Warning: mysqli::close() [function.close]: Couldn't fetch mysqli in
/home/path/to/test.php on line 56
--
Edit bug report at http://bugs.php.net/?id=36949&edit=1
--
Try a CVS snapshot (PHP 4.4):
http://bugs.php.net/fix.php?id=36949&r=trysnapshot44
Try a CVS snapshot (PHP 5.1):
http://bugs.php.net/fix.php?id=36949&r=trysnapshot51
Try a CVS snapshot (PHP 6.0):
http://bugs.php.net/fix.php?id=36949&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=36949&r=fixedcvs
Fixed in release:
http://bugs.php.net/fix.php?id=36949&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=36949&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=36949&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=36949&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=36949&r=support
Expected behavior: http://bugs.php.net/fix.php?id=36949&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=36949&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=36949&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=36949&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=36949&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=36949&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=36949&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=36949&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=36949&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=36949&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=36949&r=mysqlcfg