10 Things to Avoid in PHP 7 10 things you should avoid When using PHP 7. (r)
PHP 7 Top Practices and Things to Avoid in PHP 7
- Do not use mysql Functions
- Do not waste your time writing code
- Do Not Utilize PHP Close Tags
- Do not Utilize a Reference If Not required
- Do not execute queries In A Loop
- Do not use * when you are querying SQL
- Don't rely on the input of users
- Do not try to be Clever
- Do not reinvent the wheel
- Do not forget other Languages
1. Avoid using mysql_ functions
It's finally the time when you'll never be asked to stop using mysql's
functions. PHP 7 will remove them completely from the core, which means you'll need switch to more efficient mysqli_
functions, or a more adaptable PDO implementation.
2. Don't write code that is a waste of time.
This is a natural choice however, it can become more significant as speed increases with PHP 7 may hide certain issues. Don't settle for the performance of your website just due to the fact that switching to PHP 7 improved speed.
3. Do Not Use PHP Close tags at the end of an file.
If you take a look at the majority of core WordPress documents, they do not contain the PHP tag when a file is tagged by PHP code. It is actually the Zend Framework specifically forbids the usage of PHP tags. They aren't required to be used in PHP and by not putting it at the end of the file , you're being sure that any whitespace that is not put in.
4. Do not be a reference If You Really Do Not Do You Need It
Personally, I'm not a fan of passing reference information. It is true that in some situations it is advantageous, but in other situations it makes code harder to follow and understand, particularly, it makes it hard to predict the outcome.
It seems that people believe that it speeds up the process, but according to a an eminent PHP programmer is not true.
A good example of how you should not use a reference is because they're not good for PHP that is built within the shuffle()
or sort()
. In lieu of returning a sortable or sortable array, they modify the source code. This does not make sense to me.
5. Do not perform queries within Loops. Loop
Looping database queries is a waste of time. It puts unnecessary strain on your system, and it's probable that you will see the same results efficiently outside of the loop. If there is something that requires this, it is possible to do so. be needed I can usually fix the issue by with two different queries I make use of to generate an array of data. Then, I loop through the array and do not need to make queries during the loop.
Do you want to learn the methods we've used to increase traffic over 1000 percent?
Join the 20,000+ subscribers to our weekly newsletter which contains exclusive WordPress tips!
6. Don't Use the character * when you are using SQL Queries
This one is mostly problem that is a MySQL issue, but the majority of us write our SQL codes in PHP and I'm of the opinion that it's a fair game. In any case, don't employ wildcards in SQL queries if you're in a position to be able to avoid them, particularly if you have a database with a lot of columns.
You should specify which columns that you require and then only take those columns. This can help limit your usage of resources, secure your data , and help make the process so clear as possible.
When using SQL Be aware of your SQL functions, and attempt to test their the speed they can achieve as much as possible. If you are calculating sums, aggregates or other similar numbers make use of SQL functions instead of PHP functions. If you're not sure of the efficiency of your query take a look and explore other alternatives - then choose the best one.
7. Beware of User-Input from Users
It is not wise to trust information provided by users. Always ensure you are sanitizing, filtering and filtering and also escape verify and utilize fallbacks. Three problems with user data Programmers don't take into account every scenario that could be possible to take into account the possibility of error, which is often or intentionally crafted.
A well-organized security program will protect you from each of the above. Make sure you use the built-in functions available, like filters_var()
to check for the correct values, and escape , as well as other functions while working with databases.
WordPress offers a variety of useful tools available to assist you. Look over the validation, escape and cleansing user data section for more details.
8. Do not try to be clever.
The goal is to write code in a way that conveys your goals with maximum clarity. There is a possibility that you can shave off an extra 0.01 second from each page by condensing everything down to single-letter variables using multi-level ternary logic or various other tricks, but that is nothing compared with the harm you'll be causing yourself and everyone who is in the vicinity.
Make sure you label your variables appropriately and record your code. opt for clarity over conciseness. Also, make sure you make use of standard object-oriented programming which is more or less self-documenting without the need for numerous comments inline.
9. Don't try to reinvent the wheel
From color-manipulation instruments to instruments, loggers and loggers including profilers, unit-testing frameworks, from Mailchimp APIs and Twitter Bootstrap Everything is available at the push of a button (or typing of a command) Use these!
10. Never overlook other Languages
If you're getting good results with these tools but what are your thoughts on Ruby, Ruby on Rails development of applications with Android, iPhone, Windows Phone? It's easy to think you'll gain nothing by these tools since they are outside of the normal routine and work requirements However, that's not what's important. Every language has something interesting to learn and sharing knowledge be beneficial. There's no reason to believe that the top PHP developers have a good understanding about programming languages from other languages!
Save time, costs and improve site performance by:
- 24/7 help and support assistance from WordPress hosting specialists all hours of the day.
- Cloudflare Enterprise integration.
- Global reach with 29 data centers worldwide.
- Optimization by using our built-in Application to monitor the performance.
This post was first seen on here