dopetalk

Technology => SMF Forum Code Modifications => Topic started by: Chip on June 11, 2021, 01:37:53 PM

Title: Writing to the php-error-log and/or file with var_dump
Post by: Chip on June 11, 2021, 01:37:53 PM
from: https://www.justinsilver.com/technology/writing-to-the-php-error_log-with-var_dump-and-print_r/

Code: [Select]
function var_error_log( $object=null ){
    ob_start();                    // start buffer capture
    var_dump( $object );           // dump the values
    $contents = ob_get_contents(); // put the buffer into a variable
    ob_end_clean();                // end capture
    error_log( $contents );        // log contents of the result of var_dump( $object )
}

$object = $variableToLog;
var_error_log( $object );

or to a file ...

Code: [Select]
                ob_flush();
                ob_start();
                var_dump($variableToLog);
                file_put_contents("dump.txt", ob_get_flush());
SimplePortal 2.3.6 © 2008-2014, SimplePortal