By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,398 Members | 1,362 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,398 IT Pros & Developers. It's quick & easy.

"function_exists" Returns Nothing

P: n/a
Has anyone had experience with "function_exists" 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_functions" 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_exists('foo')) evaluates as false (so does
if(function_exists('foo') == true), for that matter)

5. print_r(function_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_functions, 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

Jul 17 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Try this code:

ini_set('display_errors', 1);
error_reporting(E_ALL);
if (function_exists('foo')) {
echo "This function exists";
} else {
var_dump(function_exists('foo'));
foo();
}

Jul 17 '05 #2

P: n/a
Try this code:

ini_set('display_errors', 1);
error_reporting(E_ALL);
if (function_exists('foo')) {
echo "This function exists";
} else {
var_dump(function_exists('foo'));
foo();
}

Jul 17 '05 #3

P: n/a
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(function_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...nothing. Not even a false.

Deane

Jul 17 '05 #4

P: n/a
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.

Jul 17 '05 #5

P: n/a
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_functions, ugly as that sounds.

Jul 17 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.