Skip to main content

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, sanitize, escape, check and use fallbacks.
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.

Comments

Popular posts from this blog

Sass

Sass: Here we are now introducing some other facts about the Sass Css Framework. Sass is the latest framework of css that is trending now very fast and it's professional, mature and powerful grade css version comparing to old versions. The Sass css is adapted by bootstrap also and other framework also so it is going fastly worldwide and many more industries are not moving to Sass. Basically Sass is the precompiled css version. It is help to load the page fastly then older css versions. Sass can be compiling through Gulp Js, Grunt and other compiler software also. It is latest version but still it is compatible with the all old versions of the css frameworks. It is working with the dynamic variables like for colors, spacing and different sections containers etc. Like, in this css framework the value of color is described once in variable but the variable can be used multiple time and in many files so if we want to change the color so we just have to change at one place...

Learn Angular 4 from scratch

Angular 4 is the latest version of AngularJs released in March 2017. The basic steps to accomplish our first Angular 4 hello world example. Here, we’ll simply create a component that passes the title from component to the view. 1. Install Angular CLI The Angular CLI is a command line interface that helps to scaffold and build angular apps in Node.js style. Also, it set up the angular 4 environments and will be helpful for us to work with angular apps like creating, running, etc. Now, install Angular-CLI. <code>npm install -g angular-cli</code> Once installation is done, just make sure that it’s installed by checking it’s version. <code>ng -v</code> 2. Install an Angular 4 Hello World App Here, we will create an app named hello-world ng new hello-world Now, go to the directory of a newly created project. cd hello-world Before running your app, let’s dive a bit deeper in coding behind the picture. 2.1 Fi...

3 Node.js Alternatives To WordPress

3 Node.js Alternatives To WordPress As compare to WordPress there is alternative option like Node.js. There are many various latest challengers that have large communities, support themes, plugins and are easy to install on your own server. Here are 3 you might want to checkout. KeystoneJS KeystoneJS is a content management system and framework to build server applications that interact with a database. It is based on the Express framework for Node.js and uses MongoDB for data storage. It represents a CMS alternative for web developers who want to build a data-driven website but don’t want to get into the PHP platform or large systems like WordPress. EnduroJS Enduro.js offers a fast and easy way to build your project, beautiful and simple admin UI and integrated tools to build everything on the server. It works without a database, instead relying on a system of flat files that can be opened directly in a text editor. It is easy to install and can be deployed via Git. ...