0

Possible Duplicate:
In PHP, how do I check if a function exists?
PHP: How to check if extension is installed?

In my site there is an installation script. I want to check that basic PHP functions are supported on a given server in that section.

How can I do that? Is it possible to check the server support for basic functions?

ex:gd

Community
  • 1
  • 1
Mariya Davis
  • 11
  • 1
  • 6

3 Answers3

1

I'm assuming you actually want to check if a function exists, and PHP has a function that does that called function_exists().

$exists = function_exists('some_function'); // Returns false, unless you defined that
// To check if PHP-GD is installed, just check if a function
// from that library exists.
$gd = function_exists('imagepng');

This works for PHP pre-defined functions as well as any user-defined functions.

animuson
  • 53,861
  • 28
  • 137
  • 147
  • 1
    I'm confused as to why this has a downvote. At the moment I think it's the best answer. – Levi Morrison Nov 18 '11 at 04:23
  • @Levi: I think someone just downvoted because there are possible duplicates that I didn't look for because I came here from the review page. -.- – animuson Nov 18 '11 at 04:24
  • i want to check all basic php functions are supported in server.How can i Check it all? – Mariya Davis Nov 18 '11 at 04:28
  • @Mariya: What do you mean by *basic* functions? Like simple ones such as `strtoupper()` and stuff? Most of those are always included by default, it would be unlikely that you'd ever find a server that doesn't have, for example, `strtoupper()`. – animuson Nov 18 '11 at 04:31
  • In my site i used some functions but that are not working.How can i check the functions i used wheather installed iin the sever or not? – Mariya Davis Nov 18 '11 at 04:34
  • @Mariya: You can use this function for all of them. Just replace the text parameter 'imagepng' with the name of the function. – animuson Nov 18 '11 at 04:36
  • then how can i check which functions are used in my site – Mariya Davis Nov 18 '11 at 04:37
  • @Mariya: If the functions don't exist and the installation script tries to call them, it should send an error which would tell you exactly which function it tried to call which doesn't exist. Make sure you have error reporting on with `error_reporting(E_ALL)` and look for any errors that come up on the page. – animuson Nov 18 '11 at 04:40
0

You want the function_exists() function. You can see it used here, for example.

artlung
  • 33,305
  • 16
  • 69
  • 121
0

Take a look at this function: http://php.net/manual/en/function.function-exists.php So, if you need, for example, CURL, you may check if it exists using something like this:

if( function_exists('curl_init')==TRUE ){
    // do something
}
Timur
  • 6,668
  • 1
  • 28
  • 37