Alex Alex - 1 month ago 8
PHP Question

PHP: is_callable("Date") === true

Today I spent 4 hours trying to find bug in the code. I was so excited to know that the string "Date" is a callable type. It is so implicit but it's a fact (PHP 5.6.26):

% php -a
Interactive shell

php > var_dump(is_callable("Date"));
bool(true)


What do you think this is a bug or a feature?

P.S. I couldn't find any information about this strange behavior in Internet.

Answer

new Date(); the class is NOT equal to date(); the function,

so date() is a callable function,

the class Date() is not callable,

only if you set up the magic __invoke() method.

And as noted in commends before php functions are not case sensitive.

So you think you test the class with is_callable(“Date”) === true

but you are testing the function with it.

Comments