3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Tmp { function __destruct() { var_dump("destroying"); } } $tmp = new Tmp(); $fn = function () use ($tmp) { $tmp = 42; var_dump("closure executed"); }; var_dump("closure defined"); unset($tmp); var_dump("original var unset"); $fn();
based on 2cd7s
Output for 7.3.0 - 7.3.28, 7.4.0 - 7.4.16, 8.0.0 - 8.0.3
string(15) "closure defined" string(18) "original var unset" string(16) "closure executed" string(10) "destroying"