Before doing something with $error:
$error = NULL;
In some script's saw:
$error = '';
$error = false;
$error = 0;
Depends on your design:
NULL
.true
in case of error? Use false
.0
.''
.A better way to indicate errors would be throwing Exceptions though, rather than setting a variable and determine the error according to it.