<?php class ResourceType { public function __destruct() { echo "Resource is released.\n"; } } function get_callback() { $some_resource = new ResourceType(); $fn = function() use ($some_resource) { // this line does nothing // it overwrites a local variable which is never read // next time the closure runs, it will start again as the captured value $some_resource = null; }; return $fn; } $fn = get_callback(); echo "Before callback\n"; $fn(); echo "After callback\n"; unset($some_resource); echo "After destroying outer var\n"; // the captured reference is still live here; only destroying the closure frees it unset($fn); echo "After destroying closure\n";
You have javascript disabled. You will not be able to edit any code.