Search code examples
phpphp-5.3

Is closures Object?


I am talking about Closures with some friends of a Group (from PHP 5.3).

When I do a var_dump(function(){}); the result is object(Closure). One of peoples said: but Closures are not Object.

I understand what when Anonymous Function implements Closure class, the result need to be a Object, nothing more or different.

Is a anonymous function a object?

UPDATE I have read "Anonymous functions are implemented using the Closure class." (http://php.net/manual/en/functions.anonymous.php), so, I think this is a Object.


Solution

  • Strongly worded in the manual:

    Anonymous functions, implemented in PHP 5.3, yield objects of this type [Closure]. This fact used to be considered an implementation detail, but it can now be relied upon.

    http://www.php.net/manual/en/class.closure.php

    To be clear, the answer is: yes, they are objects.