0

Why does function_exists("empty")return false?

if (function_exists("empty")) {
    echo "Not working";
}

Documentation states the following for function_exists:

Checks the list of defined functions, both built-in (internal) and user-defined, for function_name.

As far as I know empty is a defined and built-in function.

2
  • 4
    This is where reading the actual PHP docs helps: empty() is not a function, it is a language construct Commented Aug 14, 2014 at 10:12
  • @MarkBaker No need to be cheeky Commented Aug 14, 2014 at 10:18

1 Answer 1

5

Empty is not a function. According to manual:

Note: Because this is a language construct and not a function, it cannot be called using variable functions.

https://www.php.net/manual/en/function.empty.php

Sign up to request clarification or add additional context in comments.

3 Comments

Is there any way to check if it exists?
@MarkBaker Of course, but I'm writing a validation class that can take any php function and execute it with a specfied value. So I have to check that the function exists...
@lawls Consider using call_user_func() or call_user_func_array() in this case, it will return === false in case the function does not exist.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.