简体   繁体   中英

PHP: Detect required version

How could I detect which version of PHP my PHP script requires? The general version like PHP5 or PHP4 could I know myself, but there are some function which are added not in the minor relase.

One of the ways is:

if (!function_exists('function_name')) {
    // the PHP version is not sufficient
}

Use phpversion() . Also, you can use it to tell the version of an extension, with an optional parameter, phpversion ([ string $extension ])

PHP manual entry

今天我找到了适合的脚本/解决方案: PHP_CompatInfo(PEAR)

Pretty much this falls on you, as the developer, knowing what functions you are using and whether they are very new and require newer versions of PHP to run or not. All it takes is one function introduced in a newer version of PHP to make it only as compatible with that version and newer.

you can put your code or class to the input here: online php shell

then check the '+ unsupported versions' checkbox and click the eval() button. based on the results you will se which versions of php had problems with your code.

example i received because of namespaces:

Output for 4.4.2 - 4.4.9, 5.1.0 - 5.2.17
Parse error: syntax error, unexpected T_STRING in /in/s3EIj on line 9
Process exited with code 255.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM