Fixed various php Notice & Warning errors

Changes are all commented with // GaryA -
with some explanation for the change. Mostly fixing uninitialised variables.