W3docs

How to print a debug log?

To print a debug log in PHP, you can use the echo function to output a string to the web page or the print_r function to output the contents of a variable.

To print a debug log in PHP, you can use the echo language construct to output a string to the web page or the print_r function to output the contents of a variable. Here's an example:

Example of printing a debug log in PHP

<?php

$x = 10;
echo "The value of x is: $x";
print_r($x);

<div class="alert alert-info flex not-prose"> Watch a course <span class="hidden md:block">Watch a video course </span> Learn object oriented PHP</div>

You can also use the var_dump function to output the contents of a variable, including its type and size. Here's an example:

Example of using var_dump() function to output the contents of a variable, including its type and size in PHP

<?php

$x = array(1, 2, 3);
var_dump($x);

If you want to output a debug message to a log file, you can use the error_log function. Here's an example:

Example of using error_log() function to output a debug message to a log file in PHP

<?php

error_log("This is a debug message");

By default, the error_log function will write the message to the server's error log. You can also specify a custom log file path or send the message via email by adjusting the function's parameters. These built-in tools provide quick ways to inspect variables and track debug information during development.