php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #62794 print_r with debug_backtrace overwrites member variable
Submitted: 2012-08-10 20:43 UTC Modified: 2012-08-14 16:01 UTC
From: burakg at torreycommerce dot com Assigned:
Status: Not a bug Package: MySQLi related
PHP Version: 5.3.15 OS: CentOS 6.3
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: burakg at torreycommerce dot com
New email:
PHP Version: OS:

 

 [2012-08-10 20:43 UTC] burakg at torreycommerce dot com
Description:
------------
Calling print_r(debug_backtrace()) from a method of a class that inherits from 
mysqli overwrites the error member variable. Calling debug_backtrace() on its own 
doesn't seem to cause any problems, but when combined with print_r, this problem 
results.

Test script:
---------------
<?php
class Db extends mysqli {
	function f() {
		$this->query("select");
		var_dump($this->error);
		print_r(debug_backtrace(), true);
		var_dump($this->error);
	}
}

$db = new Db("host", "user", "password", "database");
$db->f();

Expected result:
----------------
string(146) "You have an error in your SQL syntax; check the manual that 
corresponds to your MySQL server version for the right syntax to use near '' at 
line 1"
string(146) "You have an error in your SQL syntax; check the manual that 
corresponds to your MySQL server version for the right syntax to use near '' at 
line 1"

Actual result:
--------------
string(146) "You have an error in your SQL syntax; check the manual that 
corresponds to your MySQL server version for the right syntax to use near '' at 
line 1"
string(0) ""

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-08-11 08:19 UTC] laruence@php.net
-Status: Open +Status: Not a bug
 [2012-08-11 08:19 UTC] laruence@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

when you print_r the mysqli object, it will can a static method of mysql , which 
also be considered as a operation,  if it was executed successful, then empty 
error info will be set.

following method act the same :

class Db extends mysqli {
        function f() {
            $this->query("select");
            var_dump($this->error);
            print_r($this, true);
            var_dump($this->error);
        }
}
 [2012-08-14 16:01 UTC] burakg at torreycommerce dot com
Hey, thanks for taking a look at this.

This behavior seems confusing since printing is usually considered a read-only 
operation on an object. In any case, I am interested in learning about the 
rationale but I couldn't find the place where it's documented, could you provide a 
link?
 
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Sun Jan 23 19:03:44 2022 UTC