Fixing $this reference in function called in static env