Question

My server is running PHP 5.2. Is there a collection of shims so I can use a least some new ability of PHP 5.3 in PHP 5.2? like:

<?php if ( !defined('__DIR__') ) define('__DIR__', dirname(__FILE__)); ?>

Was it helpful?

Solution

I can't recall all the features 5.3 and 5.4 brought to the table but the short answer is: no.

5.3: Feature you mentioned (__DIR__ constant) is impossible to replicate unless you want to start every file with mentioned declaration (remember every file has different location).

5.3: Closures can be simulated using create_function() but context passing with use() or any new syntax won't be accessible.

5.4: Traits can be simulated using external configs and __call() handlers, but you'll need to write or inherit them in every class.

5.4: Short array syntax is, well, impossible.

The list goes on (binary notation, array item dereferencing, etc.) but answer is still - no.

As for one example where it worked, there is a "polyfill" for PHP 5.5's array_column() function, you can find it below. It's too long to include in answer, so please don't vote it as link-only.

http://benramsey.com/blog/2013/07/the-array-column-php-userland-library/ https://github.com/ramsey/array_column

Look also at the project which emulates all functions brought up in PHP 5.1 and up: https://github.com/Polycademy/upgradephp

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top