Don't use $this in anonymous function

The $this variable wasn't allowed in anonymous functions until 5.4;
Mitigate this by using a $context variable and passing it into the scope.

I looked and it seemed like this was the only occurence of the problem throughout the codebase.

Fixes #2143 from what I can see.

@myevit can you verify this fixes your issue?