Skip to Main Content
PHP in a Nutshell
book

PHP in a Nutshell

by Paul Hudson
October 2005
Intermediate to advanced content levelIntermediate to advanced
372 pages
11h 35m
English
O'Reilly Media, Inc.
Content preview from PHP in a Nutshell

Name

function_exists()

Synopsis

    bool function_exists ( string function_name )

If you're working with functions that are not part of the PHP core (i.e., that need to be enabled by users), it's a smart move to use the function_exists() function. This takes a function name as its only parameter and returns true if that function (either built-in or one you've defined yourself) is available for use. It only checks whether the function is available, not whether it will work—your system may not be configured properly for some functions. Here is how it looks in code:

    if (function_exists("imagepng")) {
            echo "You have the GD extension loaded.";
    } else {
            echo "Can't find imagepng() - do you have GD loaded?";
    }

Tip

If you ever want to know whether you have a function available to you, use the function_exists() function. This takes one string parameter that is the name of a function and returns true if the function exists or false if it does not. Many people use function_exists() to find out whether they have an extension available, by calling function_exists() on a function of that extension. However, this is accomplished more easily with the extension_loaded() function, covered in the next section.

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

PHP Cookbook

PHP Cookbook

Eric A. Mann
Programming PHP

Programming PHP

Rasmus Lerdorf, Kevin Tatroe
Learning PHP

Learning PHP

David Sklar

Publisher Resources

ISBN: 0596100671Errata Page