Web developers either love it or hate it but can’t live without it. All those horrible underlines and nested function calls. If only it were as pretty as C++.
While PHP7 has taken a few tips from higher languages, (more data typing), if you didn’t like the look of PHP5 you probably won’t fancy its big sister any better at first sight. But personality matters more than appearance: PHP7 is going to speed up the Web, site by site (82% of them anyway).
Strangely, programmers in C or Java take pride in writing fast lean code even though today’s processors often don’t need it. Web developers, however, are prone to churn stuff out to achieve the desired result without paying enough attention to the way it actually executes. Secretly we knew this couldn’t go on forever: to benefit from PHP7’s speed and frugality we have to mend our wicked ways.
PHP7 is twice as fast as PHP5 but how much faster will your site load? if everything else on your site wastes time, space, memory and bandwidth – not much. To benefit from faster code, you need to optimise the whole site.
One-size-fits-all CMS like WordPress and their off-the-peg mods contain large portions of code superfluous to any given site. Fast PHP is a strong argument for lean bespoke development.
Stop using mysql_
PHP7 is as backwardly compatible as possible but mysqli_ functions have replaced it. Alternatively, use PHP data objects.
Don’t end files with ?>
It allows invisible line endings to trail the tag with a lot of undesirable consequences.
Passing by reference
If, like many developers, you find other people’s PHP hard enough to follow as it is, throwing in a reference when a value is available is just plain mean. PHP is intended for straightforward purposes like putting information on a screen. Fancy data manipulations are the domain of higher languages so if you need to do it perhaps you should be looking at those.
It’s a bit like catching multiple buses to the shops to buy one item at a time. Create an array with a preliminary query and extract what you need from that.
If you ever work with a corporate database without being precise and frugal it will soon be noticed.
Parse all input for correct form. A developer once trashed a company database by entering a short date when it expected a long one (although to be fair, it was osCommerce).
Websites are collaborative. Please leave your code as you would wish to find it; sensibly named, consistently structured, and annotated. Brilliant coders who don’t value simplicity are lousy programmers.
If you’re married to PHP take a mistress
The more you exercise with other frameworks and scripting languages, the better your PHP becomes too.
Google has made originality a sin. Developing something that has been developed before is really just procrastination.
Written by Matthew Kimani – PHP Web Development Talent Sourcing
Linkedin – https://www.linkedin.com/in/mathew-kimani-52a3aa25/