Correct scope used inside heredocs with embedded code