When I use an anonymous function ( but see also note below ) like :
$f = function() use ($out) {
echo $out;
};
It produces an parse error on servers where PHP is older than 5.3.0
.
My software needs to be compatible with unknown servers , but in the same time , I want also to use new functions, so I thought I will add some kind of a version check,
if (o99_php_good() != true){
$f = function() use ($out) {
echo $out;
};
}
where the o99_php_good()
is simply
function o99_php_good(){
// $ver= ( strnatcmp( phpversion(),'5.3.0' ) >= 0 )? true:false;
$ver= ( version_compare(PHP_VERSION, '5.3.0') >= 0 )? true:false;
return $ver;
}
But still the error is produced .
Is there a way to somehow "isolate" that part of the code ?
I thought of doing a conditional include()
based on a version check , which would probably work, but it will be absurd to make a separate file every time I need to use a function...
Any creative ( or trivial ) solution for that ?
Note : the example here is just a Lambda function, but the problem can occur in every other function which is a new feature and/or might not be supported on some servers ..
Edit I after comment .
Adding a "minimum requirements" list is always good, but it does not resolve the problem.
If one does not want to loose users (not all customers are happy or can upgrade their servers every time I will update a new function ) it will just force me to "fork" my software into 2 (or possibly more ) unmanageable versions..