Search code examples
phpvar-dump

A var_dump equivalent for sending data with email


I've been looking for a php library that allows me to send formatted data (like krumo) for variables via email.

This is because I've created an error handler that sends an email with the data on production environment.


Solution

  • You could json_encode() or serialize() the data if you want it to be machine readable.

    If you want it to be human readable, you can either supply the second argument TRUE to print_r() to return the data as a string, or use output buffering to catch the output of var_dump() into a string.

    e.g.

    // For machine-readable results
    $dataStr = json_encode($data);
    // ...or...
    $dataStr = serialize($data);
    
    // For human-readable results
    ob_start();
    var_dump($data);
    $dataStr = ob_get_clean();
    // ...or...
    $dataStr = print_r($data, TRUE);