4

Along with the introduction of Closures in PHP 5.3, has been introduced a getClosureThis() method on ReflectionFunctionAbstract.

Anyone has an idea what it is for? The doc does not say anything about it, Google has been useless so far, and my attempts on different ReflectionFunction/ReflectionMethod objects have all returned NULL.

BenMorel
  • 34,448
  • 50
  • 182
  • 322

1 Answers1

3

As it says:

Returns this pointer bound to closure

So if you have PHP 5.4:

<?php
class MyObj {}
$foo = function() { };
$obj = new MyObj;
$foo = $foo->bindTo($obj); // Inside the newly returned closure, $this == $obj
$reflector = new ReflectionFunction($foo);
assert($obj === $reflector->getClosureThis());

i.e., It returns the closure's $this pointer.

BenMorel
  • 34,448
  • 50
  • 182
  • 322
Matthew
  • 47,584
  • 11
  • 86
  • 98