artcoder — 2010-10-15T21:42:22-04:00 — #1
I'm trying to figure out what some PHP code is doing. In particular, I need to see inside the structure of some of these PHP object variable. I'm doing
but it blocks program flow when it displays things to the page. And I see it display "Array()" on a white page. What does that mean? An empty array?
How I can do a print_r to a log file?
Or is there a better way to examine what goes on in PHP code?
logic_earth — 2010-10-15T21:46:23-04:00 — #2
Use an editor or IDE that has PHP debugging capabilities.
I use Komodo IDE with xdebug.
artcoder — 2010-10-15T21:58:41-04:00 — #3
Except, I'm debugging code on the server (test application on a test server on a shared webhost). I don't have a local PHP development environment. I have to use things like debug_backtrace(), var_dump, etc. But they all seem to print to page.
logic_earth — 2010-10-15T22:00:44-04:00 — #4
dibley — 2010-10-16T08:41:40-04:00 — #5
I use the following lines which explode out the array and show you what is contains in a easy to read format ( well to me)
just insert, and doesnt seem to stop code running either.
hope it helps
ahundiak — 2010-10-16T08:59:37-04:00 — #6
"If you would like to capture the output of print_r(), use the return parameter."
After which you could dump it to a log file.
But do yourself a favor and setup a local development machine.
artcoder — 2010-10-16T11:29:22-04:00 — #7
What I have learned...
a) Set up a local dev environment with Komodo IDE and xdebug.
b) But in the mean time, I can do ...
$debugsomeStuff = print_r($someStuff,true);
and the stuff will show up in my error_log at the root of my application.
dowhile — 2010-10-16T13:59:47-04:00 — #8
Path to error_log is based on server and ini settings.
Here is what I use:
@ini_set('error_log', LOGS_DIR . '/error_php_' . date('Ymd') . '.log');
as you can see, I use ini_set to set path and file name of error log. In my default setting errors goes to Apache error log.
artcoder — 2010-10-16T14:18:11-04:00 — #9
What file to you put those @ini_set?
anthonysterling — 2010-10-16T15:20:06-04:00 — #10
No, those function calls would go in your PHP script, or entry-point for your application.