📜 ⬆️ ⬇️

How to forget about the version of PHP used

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, there may be a problem with the lack of familiar functions or their incorrect work.

Example.
Literally, I just needed to automate the work of the content manager of one of the sponsored sites. The necessary class was found quite quickly (post via XML-RPC), the necessary functionality was added. Verification (local) showed that everything works 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 branch). After a quick glance, it turned out that the problem was in a single function - file_get_contents, to which the ability to get a file using the POST method was added, for example.

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

In the case of the example above, I just got the desired function from the package, inserted it into the code and it all worked. 30 seconds instead of rewriting the miraculous code and debugging the resulting one.


Use - easy. You can simply 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';

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


All Articles