0

I have a very complicated system which was opening and closing MySQLi connections every time it wanted to perform a query - of which it was doing about 40,000 of per given operation (inefficient, I know). I decided to pass the mysqli connection between functions, to prevent this open-and-close-repeatedly inefficiency.

My problem is: when a query fails I wanted to email myself the debug_backtrace(), formatted in an easy-to-read format (so I wrap it in print_r()). For some reason, I'm now getting a PHP warning that says print_r(): Property access is not allowed yet in... on line XXX where line XXX simply reads addNotification("Backtrace: ".print_r(debug_backtrace(), true), "debug");

Is there some reason that print_r() doesn't like debug_backtrace() when one of the passed parameters in the backtrace is an mysqli_connect object? Does the mysqli_connect lack a toString function?

EDIT After a little more research I've found that you CAN call print_r or var_dump on a mysqli_connect object, but if that object is mysqli_closed it causes this warning. If it is closed and unset it is okay.

Bing
  • 3,071
  • 6
  • 42
  • 81

1 Answers1

-1

See the example here.

http://php.net/manual/en/function.debug-backtrace.php

it's using var_dump instead of print_r

my personal favorite is var_export, because it creates php readable format.

Richard
  • 1,045
  • 7
  • 11