faqts : Computers : Programming : Languages : PHP : Function Libraries

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

21 of 25 people (84%) answered Yes
Recently 7 of 10 people (70%) answered Yes

Entry

Is function_exists() case sensitive?
Are function names case sensitive in PHP?
The function MyTest exists, why does function_exists("MyTest") return false?

Jun 30th, 1999 21:21
Nathan Wallace, Christopher W. Curtis, Brian Schaffner, Jim Winstead


The function_exists() function looks for the function name exactly as
you type it (case sensitive). Unfortunately, all function names are
stored internally in lower-case. So, MyTest() doesn't exist, but
mytest() does.

This is a bug in PHP versions earlier than version 3.0.8.

Just to illustrate, the following will not work as expected:

    <?php

    Function MyTest( )
    { }

    $var = "MyTest";
    if( function_exists( $var ))
        echo "yes via var<p>";
    if( function_exists( "MyTest" ))
        echo "yes via string<p>";
    echo "Done.\n";
    ?>

For correct results, change the above to this:

    <?php
 
    Function MyTest( )
    { }
 
    $var = "MyTest";
    if( function_exists(strtolower($var)))
         echo "yes via var<p>";
    if( function_exists(strtolower("MyTest")))
         echo "yes via string<p>";
    echo "Done.\n";
    ?>

and you should get the expected output.