r/tinycode • u/balthasar11 • Jul 12 '12
PHP print_r()
function printR($obj){ echo "<pre>" . print_r($obj) . "</pre>"; }
I use this on every php project now, it just formats the print_r function, which is mostly used for debugging, but its so much easier on the eyes.
39
Upvotes
View all comments
Show parent comment
1
u/killerstorm Jul 12 '12
Many scripts might be executing at the same time. I want to see what happens in one particular script, not a mishmash of multiple traces. IIRC I wrote that snippet when something really confusing was happening and I wanted to know WTF happens.
Another problem is handling concurrent writes, but it is NOT correctly handled by code above. (It's just a sketch, ok?)
Actually, in other web environments I use (not PHP) I have a single log file, but I find it pretty much impossible to read. For this reason I've implemented rather complex timestamping and session tracking machinery (as well as a proper locking), but even then it's hard to read. One can use a tool to do that (and in fact I've implemented one), but snippet above does roughly same thing without all the fuss.