Anfurny
Anfurny

Reputation: 134

Way to achieve backwards compatibility from PHP 5.3 to 5.2 (Pre processor directive?)

I have written a cool little PHP library but it makes use of closures which cause a PARSE ERROR (not a runtime error!) when I run the app on my webhost (1and1). What I would love is something like a c++ preprocessor directive or an CSS version-specific comment that basically ignores a segment of code for PHP < 5.3

$this->register_validator(
    function($val) use ($length_expr)
    { 
        $x = strlen($val);
        return eval("return $x $length_expr;");
    }
);

Upvotes: 0

Views: 441

Answers (1)

deejayy
deejayy

Reputation: 770

I think there is a syntax error, which causes the parse error in the eval()'d code.

I tried it in PHP 5.2.17 and 5.3.6 too:

You can not return two values inmediately, like this:

return $x $legth_expr;

This is throwing a parse error in the mentioned two versions.

What do you want to achieve exactly?

Upvotes: 1

Related Questions