3v4l.org

run code in 300+ PHP versions simultaneously
<?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";
Output for git.master, git.master_jit, rfc.property-hooks
Before callback After callback After destroying outer var Resource is released. After destroying closure

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
52.87 ms | 401 KiB | 8 Q