Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to var_dump from CodeIgniter controller

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:

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

In my log file, I get:

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

I am able to get the result of:

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

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

Any ideas? Thanks for the help.

like image 213
Derek Morgan Avatar asked Jun 23 '14 17:06

Derek Morgan


People also ask

What is Var_dump () function?

The var_dump() function dumps information about one or more variables. The information holds type and value of the variable(s).

What is the difference between Var_dump () and Print_r ()?

var_dump() displays values along with data types as output. print_r() displays only value as output. It does not have any return type. It will return a value that is in string format.


1 Answers

Based on PHP var_dump() documentation, var_dump()LINK doesn't return, it only outputs.

Therefore you can use output buffering PHP function like the following:

<?php
   ob_start();
   var_dump($data);
   $result = ob_get_contents(); //or ob_get_clean()
   //ob_end_clean() 
?>
like image 91
Sobiaholic Avatar answered Oct 18 '22 19:10

Sobiaholic