You could test for "0" separately -
if ($var != 0) {
if (!intval($var)) {
$var = 'error';
}
}
It's a bit crude but it would set $var to 'error' if $var was not an integer, otherwise $var is left unchanged.
Hoe this helps 😉
P.S. There must be a better way, but this will work.