No matter how good you are in PHP coding, there is always room for improvements especially if you are working with other people. Simply put, being able to make it foolproof for others just makes your work easier to understand – and appreciate.
So, here are 3 tips to writing cleaner code in PHP:
#1: Document & Leave Comments
As mentioned earlier, it is important for people to understand why you are doing what you’re doing in certain ways. This is why adding comments can be a good idea but what will take your coding abilities to a whole new level is when you are able to document classes and functions clearly.
#2: Meaningful Names for Classes, Functions and Variables
Very often, the variables, classes and functions used could lead people astray as to what their ‘function’ really is. For example, if you named a function Scan_Incomming_Data_For_Evil() as opposed to SIDFE(), won’t it be easier for the person who is reading your code to understand what this function does.
#3: Use Comments instead of Deleting
Let’s say that you’ve fixed a bug with about 100 lines of code and this has caused something else to break in the process. Of course, you would have to go over old code in order to figure out what went wrong. This wouldn’t be possible if you are used to deleting code. So, instead of delete the code that you’ve written, it’s a better idea to leave comments saying that a particular section of code wasn’t working for other people to take not of.