"function_exists" Returns Nothing

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Deane

    "function_exists" Returns Nothing

    Has anyone had experience with "function_exist s" not finding a function
    that you KNOW you've defined? I have defined a function we'll call
    "foo":

    1. I know that function has been parsed, because code lower down the
    script executes a function in the same include file.

    2. The function name appears in the "get_defined_fu nctions" array.

    3. If I just call the function (without bothering to check if it
    exists), I get a return value, so the function is there.

    4. if(function_exi sts('foo')) evaluates as false (so does
    if(function_exi sts('foo') == true), for that matter)

    5. print_r(functio n_exists('foo') ) prints nothing to the screen.

    I've experimented with case to no success. function_exists is supposed
    to be case-insensitive, but it doesn't seem to matter. The function
    name is in lower case in get_defined_fun ctions, but looking for it with
    any type of case doesn't matter -- it's just not found.

    I have to be doing something wrong, but I can't figure out what.

    Deane

  • Philip  Olson

    #2
    Re: "function_ exists" Returns Nothing

    Try this code:

    ini_set('displa y_errors', 1);
    error_reporting (E_ALL);
    if (function_exist s('foo')) {
    echo "This function exists";
    } else {
    var_dump(functi on_exists('foo' ));
    foo();
    }

    Comment

    • Philip  Olson

      #3
      Re: "function_ exists" Returns Nothing

      Try this code:

      ini_set('displa y_errors', 1);
      error_reporting (E_ALL);
      if (function_exist s('foo')) {
      echo "This function exists";
      } else {
      var_dump(functi on_exists('foo' ));
      foo();
      }

      Comment

      • Deane

        #4
        Re: "function_ exists" Returns Nothing

        It returns nothing. I tried your code and go nothing. So I set the
        error reporting to the strictest level I possible could, and just did
        this:

        var_dump(functi on_exists('foo' ));

        Nothing. I even had to a put a die() right after it to make sure
        var_dump executed. It seems that function_exists is
        returning...not hing. Not even a false.

        Deane

        Comment

        • Philip  Olson

          #5
          Re: "function_ exists" Returns Nothing

          Then it's something else as var_dump() will always print something
          here. Always.

          My gut tells me that the display_errors directive is off in php.ini and
          a fatal error exists. In this case, display_errors cannot be set at
          runtime and you'll get a blank page.

          Comment

          • Deane

            #6
            Re: "function_ exists" Returns Nothing

            Well, I upgraded the PHP version to 4.3.11 and var_dump is now
            returning something from function_exists -- but it's false.

            I'm at a roadblock here. function_exists refuses to accept that the
            function is there, even though every other indicator comes back true.

            I think I'm just going to hack up a user function that does an
            array_search on get_defined_fun ctions, ugly as that sounds.

            Comment

            Working...