views:

244

answers:

4

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.

+6  A: 

One of the ways is:

if (!function_exists('function_name')) {
    // the PHP version is not sufficient
}
Raveren
Since mostly I would guess the issue is PHP 4 and 5, I write a function for php4 that has the same name as a function in 5 with this wrapped around it. Then I can call it as I please.
MrChrister
I think poru rather wants to know how to determine the minimum PHP version his script can work on. So the lowest PHP version where all the functions he uses are available.
Gumbo
+2  A: 

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.

John Conde
+3  A: 

Here’s a list of the functions that had been added in what version.

Gumbo
+2  A: 

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

PHP manual entry

Leprosy