My php is a little rusty but this is boggling my mind right now. I googled this and read all the stackoverflow questions I could find that looked related, but those all seem
$msg
global tells that PHP need to use the global variable in the local function scope.
global