<?php function getMsgFnc() { global $msg; return function() use ($msg) { echo "Msg: {$msg}!<br/>\n"; }; } $GLOBALS['msg'] = "Hello"; $fnc = getMsgFnc(); $fnc(); $GLOBALS['msg'] = "World"; $fnc();