Welcome Guest, Not a member yet? Register   Sign In
How to var_dump from controller
#1

[eluser]dlm1897[/eluser]
Hi all, I am attempting to do a var_dump from a controller to my log file and I'm left with an empty line.

Here's the code within my controller:

Code:
$checked = 'test error';
log_message('error', var_dump($checked));

In my log file, I get:

Quote:ERROR - 2014-06-23 12:30:34 -->

I am able to get the log file result of:

Code:
$checked = 'test error';
log_message('error', $checked);

, so it must be an issue with var_dump()?

Any ideas? Thanks for the help.

ANSWER:

I had to use output buffering since var_dump() only outputs and does not return. The following works:

Code:
ob_start();
var_dump($checked);
$result = ob_get_contents(); //or ob_get_clean()
log_message('error', $result);
#2

[eluser]CroNiX[/eluser]
Check the PHP manual for var_dump. It outputs immediately to the browser and doesn't return a string. You can capture the output as a string, though.
#3

[eluser]dlm1897[/eluser]
[quote author="CroNiX" date="1403548595"]Check the PHP manual for var_dump. It outputs immediately to the browser and doesn't return a string. You can capture the output as a string, though.[/quote]

Thanks for the response. You hit the nail on the head.




Theme © iAndrew 2016 - Forum software by © MyBB