Fixed "Using $this when not in object context" (#1174)