You should really not expect $v1 to be available outside of an if statement-- I think you're using the identifier outside of its intended purpose, and the behaviour is undefined.