How to debug a PHP Open Source Project that you don’t know

Questo articolo è stato scritto oltre 1 years, il contenuto potrebbe essere datato.

Debug is boring especially when you have a bug in a project that is not your and you don’t have idea where to look in the code.

With this article I want to share my experience about I inspect and analyse a project when I develop.

Search in the code

This is the most important piece but the question is: How I can search for something that I have no idea what is?

I use different approach on looking in the code and I usually start from the stuff printed in the browser.

Example: I have to find the method used for sanitize a text field in the website, the first step is to find the css class, the name or id and search in the code.

This can be so simple but often is not so much so you need to find an unique reference that can help you to search in the code.

From the frontend/backend usually is a good starting point because when you find the code you can alter very fast and see in the browser if you find the right one.

Search on GitHub for errors or specific problems

Open source is cool because there is sharing also of resources and problems and GitHub is the best aggregator.

Usually when I have a specific error I search on the repo or globally on GitHub. Oother than looking for the code tab (of the search page) usually is useful look also on the Commit tab for find old code that can help you to understand the changes, maybe there are comments helpful for your problem. The last step is looking on the Issues tab because maybe someone else reported my problem or something similar and I can find useful information to speed up the debug.

Search also on Google/Stackoverflow can be helpful of course 😀

Try Catch

This is the last method that I use when I got exception but I have no idea where is happening the real problem because can a cascade of methods with other try catch with similar error reporting.

// your code that thrown the exception
} catch (Exception $e) {
// print_r or anything method you use for debug
print_r($e->getMessage() . ' - ' . $e->getFile() . ' - ' . $e->getLine());

This saved my ass few times because report the file and the line because often the exception don’t report this kind of information so much in deep.


Few hints that I use in my normal life of developing but I think that can be helpful also for you, but what are your method of debugging?

Liked it? Take a second to support Mte90 on Patreon!
Become a patron at Patreon!

2 thoughts on “How to debug a PHP Open Source Project that you don’t know

    1. SI lo conosco ma è veramente molto verboso e certe volte preferisco sporcarmi le mani, l’ho usato solo una volta nella mia vita.

Leave a Reply

Your email address will not be published. Required fields are marked *