📜 ⬆️ ⬇️

My PHP 7 migration experience

image
A few days ago, I switched my server from about 30 sites to PHP 7. Some of them were quite old and made up a wide range of different frameworks and CMS. Here are some tips for those who have not yet decided to switch to PHP 7 or not.

Let's start with the fact that I understand that there are many people who do not consider a stable version really “stable” until it has matured a bit, expecting that there will be some bugs or incompatibilities. From what I've seen so far, trying every release candidate as soon as he exits, it is completely safe to switch to PHP 7 as soon as he exits. I have never noticed some incomprehensible behavior or departure which I would not have been to blame. Despite the fact that this is a new version, it does not carry many incompatible changes, that is, by and large you can treat it as just PHP 5.7 only much faster.

And the speed is really impressive, even incredible how. For example, a simple site on PHPixie earned almost three times faster, almost comparing with the speed of Phalcon on PHP 5.6, several sites on Wordpress showed a steady increase in speed twice. If we take into account the recent report from Google that the loss of even 10% of page load performance leads to a noticeable loss of customers, if you can easily speed up the website twice by updating PHP, you get more sales without spending anything. Remember this when you convince your manager to switch to PHP 7. Nothing convinces anything better than sales.

A few notes
')
The mysql extension is no longer available, so if you have not yet switched to PDO or mysqli, then now you definitely have to. Fortunately, in many cases it is enough to simply replace the calls to the mysql_ functions with mysqli_ .

E_STRICT errors are reclassified as other types of errors. If you previously hid them or ignored them, now they will begin to emerge along with others. For example, the call of non-static methods now statically throws out E_DEPRECATED, which created a lot of problems with Joomla 2.5 which for some reason does it quite often. Also incompatible inheritance is now classified as E_WARNING . Since February Wordpress has been testing to work with PHP 7, so there are no problems with it, however, several plug-ins have turned out to be incompatible.

foreach now always works with a copy of the array, so that any changes to the array during the iteration will not affect the iteration itself. In fact, in many cases it already worked and the case itself is quite rare, but I came across this in one of the plug-ins.

Now $ foo -> $ bar ['baz'] is interpreted as ($ foo -> $ bar) ['baz'] and not $ foo -> {$ bar ['baz']} as in PHP 5. This is a rare case. , but also caught in one of the plugins, and as it turned out in Magento 1.x ( core / Mage / Core / Model / Layout.php ).

Keep in mind that not all extensions support PHP 7. I can no longer use the XCache I like, which has served me faithfully for many years.

It is unlikely that you will encounter any problems other than the above, but if you are interested, then the full list is available on the PHP site .

In total, it took me about 5 hours to translate all the sites into PHP 7. The process is completely easy and the packages are already available for all popular distributions. So even if you are going to wait for a stable release (already for a very short time), there is no reason not to prepare your sites for migration in advance.

PS: Fairy in the title of the article - our holiday logo PHPixie 3, it is not quite the topic, but really wanted to share. Well, you can assume that this is PHP 7 in the bag.

Source: https://habr.com/ru/post/271181/


All Articles