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

- Development, Open Source, PHP

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.

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.

Conclusion

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?

All the stuff released in this website, where the author is Daniele Scasciafratte, is under the GPL 2.0 license except when the resources have their licenses.

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

    • 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