开发者

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 ?


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


    if (version_compare(PHP_VERSION, '5.0.0', '<')) {
        die('PHP is to old.');
    }

http://de3.php.net/manual/en/function.version-compare.php

http://www.php.net/manual/en/reserved.constants.php#reserved.constants.core

or

http://php.net/manual/en/function.phpversion.php


It can't ignore the errors, however it can die nicely if error_reporting(0);


if ((int)phpversion() < 5){
  error_reporting(0);
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜