James Bachini

Three ways to debug php

Method 1 – error.log

For this to work you need to be coding in a linux environment with php, apache etc setup. This is the best way I have found and what I currently use to debug my applications/web pages.

open up a new terminal and type:
tail -f /var/log/apache2/error.log

This will give you a readout of the last few error messages. Refresh the page you are working on in a browser and it’ll give you the fault code and line number where you probably forgot a semi-colon.

Method 2 – display all errors

Add the following lines to the top of your script:
ini_set(‘display_errors’, ‘On’);
error_reporting(E_ALL);

This will display all errors in the browser. Make sure you take it out before deployment.

Method 3 – Var Dump

If something just isn’t working but you aren’t getting an error blow the script apart by throwing a var dump into the equation. The following line will dump all defined variables into the browser.
var_dump(get_defined_vars()); //var dump all

Hope these tips will save some headaches or at least shorten the duration of them.


Get The Blockchain Sector Newsletter, binge the YouTube channel and connect with me on Twitter

The Blockchain Sector newsletter goes out a few times a month when there is breaking news or interesting developments to discuss. All the content I produce is free, if you’d like to help please share this content on social media.

Thank you.

James Bachini

Disclaimer: Not a financial advisor, not financial advice. The content I create is to document my journey and for educational and entertainment purposes only. It is not under any circumstances investment advice. I am not an investment or trading professional and am learning myself while still making plenty of mistakes along the way. Any code published is experimental and not production ready to be used for financial transactions. Do your own research and do not play with funds you do not want to lose.


Posted

in

by