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 upgrade to PHP 7 or not.

    To begin with, I understand that there are many people who do not consider the stable version to be truly “stable” until it has almost matured, expecting that there will still be some bugs or incompatibilities. From what I have seen so far, trying every release candidate as soon as it exits, it is safe to switch to PHP 7 as soon as it exits. I have never noticed any incomprehensible behavior or departure which I would not be guilty of. Despite the fact that this is a new version, it does not bring 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 in PHPixieearned almost three times faster, almost comparing with the speed of Phalcon in PHP 5.6, several sites on Wordpress showed a steady increase in speed twice. If you take into account a recent report from Google that the loss of even 10% of page loading performance leads to a noticeable loss of customers, then if you can easily speed up the site twice by simply updating PHP, you get more sales without spending anything. Think about it when you convince your manager to switch to PHP 7. Nothing convinces better than sales.

    A few notes

    The mysql extension is no longer available, so if you haven’t switched to PDO or mysqli, then you definitely have to. Fortunately, in many cases it is enough to simply replace the calls tomysql_ functions on mysqli_ .

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

    foreachNow it always works with a copy of the array, so that all changes to the array during the iteration will not affect the iteration itself. In fact, in many cases it worked already, and the case itself is quite rare, but still I came across this in one of the plugins.

    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 already support PHP 7. I can no longer use the XCache I liked that 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 not difficult and the packages are already available for all popular distributions. So even if you are going to wait for a stable release (for a short time already), there is no reason not to prepare your sites for migration ahead.

    PS: The fairy in the title of the article is our holiday logo of PHPixie 3, it’s not really in the subject, but I really wanted to share it. Well, you can assume that it is she who carries PHP 7 in a bag.

    Also popular now: