12

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.

2
  • You could look at your script and search for 'new' PHP functions... Commented Jan 25, 2010 at 16:32
  • +1 That’s a good question. Maybe there’s a script out there that can detect that. Commented Jan 25, 2010 at 16:40

6 Answers 6

10

One of the ways is:

if (!function_exists('function_name')) {
    // the PHP version is not sufficient
}
Sign up to request clarification or add additional context in comments.

2 Comments

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.
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.
5

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

PHP manual entry

Comments

4

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

1 Comment

This list could not-quite-so-difficult-ly be transduced into a form usable by such a script as the OP desires (which will be easy to write, given this data set). Great find!
4

Today I found eventual a script/solution that fits: PHP_CompatInfo (PEAR)

Comments

2

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.

Comments

1

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.