
Benjamin S. answered 11/15/19
Tutor
4.8
(112)
Lead Software Engineer Specializing in PHP
Programming in PHP can be frustrating for sure. I have spent countless hours banging my head against the wall, only to discover that I made a stupid mistake. However, I have found 3 big tips that make the error handling process much easier over the years.
- Use a Syntax Checker: For me, I like to use a text editor that has a syntax checker built in. For PHP, I love the Visual Studio Code editor as it notifies you whenever you have a syntax error. This saves a ton of time and eliminates the possibility of a syntax error whilst debugging.
- Use a Solid PHP Framework: Error handling can be completely different depending on the PHP framework that you use. This is one of the many reasons why I couldn't recommend the Laravel framework enough. Laravel is a Model View Controller framework and provides you with easy to set up logging to files or databases. Their debug mode is awesome as well as it helps you identify your issues much more quickly than you would in another framework.
- var_dump: When dealing with different third party APIs and being unsure as to how to access different data structures, I have found var_dump to be incredibly important. Per PHP's docs, it dumps information about a variable. This means that it gives you critical information about how a variable is structured so that you can access the data held within it. Is the variable an object? Is it an array? Use var_dump to see.