Debugging PHP

Debugging PHP can be a headache if you are not using any third party software/platform.

The solution I use is calling a Javascript alert box as follows:
echo 'alert("Message to display!")';

Or if you want to display a variable, do the following:
echo 'alert("'.$var1.'")';

For array, I would use this to view the array in the developer’s console:
<script>
var var_dump = <?php echo json_encode($var1); ?>;
console.log(var_dump);
</script>

If you know of any other way, let me know!

Edit: For those who use Firebug in Firefox browser, the answers in Stackoverflow here looks good: http://stackoverflow.com/questions/14995307/sending-var-dump-to-firebug-console

Advertisements