8 Things not to do in Php 7:

8 Things not to do in Php 7:

Here are thing which you should not do in PHP7. this things are not just matter of php7 some of this can be common in Programing languages, at least for quality code and improve performance.

1) Avoid writing Wasteful Code

This simply means do not write useless code which will waste your performance. In fact php7 increase speed so much that it could be hide some of problems. As a developer, you should always make sure that your application only load scripts when it is require and concatenate them when it's possible. Write database queries, use caching when possible, and so on...


2) Verify User Input

Always filter, sanitise, escape, check and use fallback. Make sure to use built in functions like filter_var() to check for proper values and escaping and other functions when working with databases.

3) Do Not Use PHP Close Tags At The End Of A file

If you noticed most php CMS and Framework files omit the ending PHP tag when a file ends with PHP code. The Zend Framework specifically forbids that it is not required by PHP. By omitting PHP close tags at the end of a file you are making sure that no trailing whitespace can be added.

4) Do Not Perform Queries In A Loop

Performing database queries in a loop is time taking and wasteful process. You achieve the same result faster with 1 or 2 queries or by creating a sub query outside of loop. If you had a situation where this would be needed just create diff queries according to your requirement and create an array of data then simply loop over data.

5) Do Not Use mysql_ Functions

PHP 7 will remove mysql_* function has been removed. That means you’ll need to move to the far better mysqli_ functions, or the even more flexible PDO or an ORM.

6) Avoid Pass By Reference If Not Needed

In some cases passing by reference is useful and necessary, but on many other occasions this just makes the code more difficult to understand and try to predict the result. Apparently, some people think that Pass By Reference makes their code faster, which according to this reference (link) (in English), is not true. An example of why referrals are bad in PHP is with respect to the built in shuffle () or sort () functions.

Instead of returning the randomized or sorted array, the functions modify the original variable, which is completely illogical to my mind.

7) Stop using * in SQL queries

It seems like MySQL database issue, but we write SQL queries in our PHP code so I think it’s worth it. Avoid using wildcard characters (*) in n SQL queries, especially when your tables have many columns. Use only those columns which you need that helps to decrease the use of system resources, makes things clearer and protects your data.

8) Do Not Reinvent the Code

PHP has been around for a long while now; websites have been made for even longer. It is possible that anything you want to do, someone else has done before.

Do not be afraid to ask from your friends Github , Composer and Packagist.