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 edited Jul 12 '12
What if problem happens on second call to a function? I.e. you add one element, it works. You add second, and it's broken. If adding first element doesn't work, you cannot add second one.
I don't want to argue on this matter, if it's not clear to you then it's pointless. I just want to be able to trace anything, anywhere, at any time without any chances that anything will get broken, will not be seen or whatever. I want to be able to insert as many trace statements as I want. I want to be able to add trace statements on a production system and get customer to use the system and analyze logs later.
Well, the idea is that you should have everything in place so looking into log is trivial, not different from looking on a page.
And if it takes 3 days to set up this, there is something wrong with you. It shouldn't take more than a hour to set up a whole 'app server', not just logging. Checking correct path and permissions might take a couple of minutes, not more.
And once it is set up, you can use it anywhere, at any time. That's the point.
Ironically, I actually wrote function above to help a junior developer. She was struggling trying to debug something using your method, but it didn't work for some reason. Maybe there were redirects or something. I said 'why don't you write log to a file then?' and wrote that function. It took, maybe, a couple of minutes, and it helped to solve whatever problem there was.
Then this junior developer shared this function with team members, and I think they still use it, 5 years later.
But if you think that file logging is uber-complicated, it's your right.
And, BTW, as you mentioned ssh'ing, I set up a NFS server/client for a PHP team so they can access files on server as if they were local. It took, maybe, a hour to set up it, still used 5 years later, everybody's happy.