Cleanup of unused variables

The php code is riddled with variables that are not being used. Probably left-overs from old and removed code. Or simply bad programming practises (like initializing the variable when it is always set in later code).

Anyway, this PR removes the bulk of those unused (memory/resource/time-hogging) variables.

#### Testing instructions
This probably just needs the general system tests to see if it doesn't break anything.