Search code examples
phpphp4parse-error

PHP 4- ignore parse errors?


I have a script that uses a PHP 5 syntax that's apparently not supported in PHP 4.

like MyClass::method()->method(...)

I'm trying to display a error at the beginning of the script telling that the server doesn't have PHP 5 installed, and "die" nicely, but I can't because I get that stupid parse error...

So how can I make PHP ignore errors if < 5 ?


Solution

  • The easiest way I can think of is to have one file that includes another if PHP5 is installed:

    //index.php
    if (intval(substr(phpversion(), 0, 1)) < 5) {
        die ('you must have PHP 5 installed');
    } else {
        include('main.php');
    }
    
    //main.php
    MyClass::method()->method(); // or whatever