Debugging closures

Opis Closure is debugging friendly and can be used in conjunction with error handlers like whoops without any special or supplemental configurations.

$whoops = new \Whoops\Run;
$whoops->pushHandler(new \Whoops\Handler\PrettyPageHandler);
$whoops->register();

$closure = function(){
    throw new \Exception();
};

$closure = unserialize(serialize(new SerializableClosure($closure)))->getClosure();

$closure();

Error 1

Opis Closure allows you to track the residing source of a serialized closure by using the #trackme directive inside the closure. The #trackme directive provides the following information:

  • Date - the date when the closure was serialized, represented in the W3C format
  • Timestamp - an integer representation of the Date
  • File - the file where the serialized closure resides
  • Line - the line where the closure can be located inside the File
$whoops = new \Whoops\Run;
$whoops->pushHandler(new \Whoops\Handler\PrettyPageHandler);
$whoops->register();

$closure = function(){
    #trackme
    throw new \Exception();
};

$closure = unserialize(serialize(new SerializableClosure($closure)))->getClosure();

$closure();

Error 1