Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In PHP, is there a way to display human-readable information about a variable in error_log()?

I want to do something like:

error_log('this is information about the variable: '.print_r($variable));

or

error_log('this is information about the variable: '.var_dump($variable));

FYI, the variable I'm trying to print is an array.

like image 852
brettgag Avatar asked Dec 09 '25 23:12

brettgag


1 Answers

print_r() accepts a second parameter which will return its output as a string. As such, your first example can be modified to the following:

error_log('this is information about the variable: ' . print_r($variable, true));

Note: While var_dump() does not have such a parameter, you could use output buffering to store its output as described in the docs.

like image 126
Jason McCreary Avatar answered Dec 11 '25 11:12

Jason McCreary



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!