Errors and a bad programming practice often frustrates the programmer and create other confusions. In this article I am will be discussing some common mistakes that beginners usually make in PHP language.
Error Handling in PHP
Suppressing the mistakes and errors is not the only way to correct the errors. A good programmer must analyze the cause of the error and how does it affect the rest of the flow of the program. When a programmer tries to suppress an error, he/she must also consider what are the other possible errors that may arise because of suppressing the previous errors. The errors must be rectified in should not create more errors in the program.
NOT TAKING INTO ACCOUNT THE COMPLEXITY OF THE CODE
A least complex program is considered to be the best and the efficient one. The programmer must use those instructions or codes that do not increase the complexity of the code. In programming terms, the complexity relates to time and space. Time complexity means the time required for executing an operation under a given condition. Hence the programming algorithm must be devised in such a way that it has the minimum time complexity. Now, talking about the space complexity, it means the storage space required for a program for its execution along with the real-time data. The storage must also be handled in such way that it uses the memory dynamically and efficiently.
NOT USING COMMENTS
A good programmer must always use comments in order to mention the use and functionality of a particular snippet of a program. It increases readability and makes the third person much easier to understand the code and its logic behind it. Most of the beginners that I came across miss on this point.
NOT SECURING THE SQL CODE
Use of simple SQL queries is not safe in web domain. The SQL queries can be modified and its meaning can be changed. If a person tries to add false information/abrupt query, one can do that with the help of SQL injections. SQL injections consist of text in such format that it modifies the existing query. In order to prevent SQL injection attacks, one must use prepared statements. This concept split the parameters of the SQL query. The parameter can be added separately using parameter binding functions.
NOT KEEPING BACKUP
It is not necessary to create back up for every change in the program but it is necessary to keep back up at some checkpoints. In case there is any loss of code, then a programmer can at least start again from the checkpoint. A good back up process must be followed. This strategy prevents hour of re-coding and important data.
NOT VALIDATING THE DATA
In web-based programming, it is very important to handle and validate the real-time data received from pages. A good programmer must use validations to check the completeness and correctness of the data received. This makes the data handling and the operations on them efficient and smooth to execute.
If you have any further queries and doubts, feel free to mention in the comment section given.