![]() |
Tip: error_log and arrays
Output buffering can be used to capture different types of output. For example, lets say your script needs to log an array, we could achieve this like:
PHP Code:
Hope this tip helps someone, it can be very useful for cron type scripts. |
As of PHP 4.3.0, there is an optional second parameter to the print_r function which is a boolean dictating whether the output from print_r is actually output (default) or returned as a string.
Your example can be therefore slightly altered to something more like: PHP Code:
|
well there you go, all that time and I never knew print_r had a second argument.
Im gunna have to update the tip now :) |
No problem, we all oftentimes just stick with what we've been doing from years and years ago. The introduction of little changes (like the inclusion of another argument) is very easy to miss, especially if the 'old' way just works fine also.
P.S. Sorry for coming in and making you edit these tips :p |
Lol np, I'm glad you did, I'll certainly be using it from now on! I just wish I didn't edit it now tbh, as it has ruined the flow of the thread. I may have to re-edit it back to how it originally was then post the updated tip below :)
|
Here's an updated example that shows how it can be used for outputting the debug backtrace to an error log.
PHP Code:
|
| All times are GMT. The time now is 05:01 PM. |
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0