How to forget about the used version of PHP

    In addition to the previous post .

    Many of us (especially freelancers) have to deal with several projects that can be located on different servers with different versions of PHP. In this case, a problem may arise with the lack of familiar functions or their incorrect operation.

    Example.
    Literally, it just took me a little to automate the work of the content manager of one of the sponsored sites. Quickly enough, the required class was found (post via XML-RPC), the necessary functionality was added. A check (local) showed that everything was working fine. But after installing on the server, it turned out that the class was written for PHP5 (on the server - one of the 4.4 branches). After a quick look, it turned out that the problem was the only function - file_get_contents, which was added the ability to get the file using the POST method, for example.


    In such cases, the PHP_Compat package can help , the main task of which is to ensure compatibility with newer versions of PHP.

    In the case of the example above, I just pulled out the desired function from the package, inserted it into the code and it worked. 30 seconds instead of rewriting the wonderful code and debugging the result.


    Use is simple. You can just take the desired function. You can use calls like:
    require_once 'PHP / Compat.php';
    PHP_Compat :: loadFunction ('file_get_contents');


    or

    require_once 'PHP / Compat / Function / file_put_contents.php';

    Also popular now: