zyriuse
zyriuse

Reputation: 73

how to debug a $result

first i have to debug a php script and i m not a php developer
i would want to have the result of $result variable in a specific file as /tmp/logging.log

 $result = $this->executeCommand("git status --branch ");

for a simple variable as $path i found how to get the value with file_put_contents

file_put_contents('/tmp/config.log', print_r( $path, true ));

could you tell me how to log the value of $result or even $this in a specific file?

thank you very much guy and have a nice week-end :)

Upvotes: 1

Views: 131

Answers (1)

Peter van der Wal
Peter van der Wal

Reputation: 11856

When you get no output in the log-file at all, it's probably because $result is either false or null. The command var_dump will give you more information on that than print_r does. Unfortunately var_dump has no extra option to return the output, so you have to use output buffering.

ob_start(); // Start output-buffering
var_dump($result); // Dump the variable (normally sent to browser, but output buffering will pick it up)
$debugInfo = ob_get_clean(); // Stop output-buffering, store output in $debugInfo
file_put_contents('/tmp/debug.log', $debugInfo);

Upvotes: 1

Related Questions