Fix scanner hooks throwing errors

"caused" by a difference in behavior with closures between 5.3 and 5.4

Should fixed #4206

cc @schiesbn @DeepDiver1975 @bartv2 @karlitschek