Answers for "error log object php"

2

var_dump to log

// Using print_r()
	$object = new MyObject();
	error_log( print_r( $object, true ) );
    
// Using var_dump()
  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 = new MyObject();
  var_error_log( $object );
Posted by: Guest on July-13-2020

Browse Popular Code Answers by Language