Fix: $error var must use type int and be increased when error found.
Using $error as boolean at some place was source of error.