You should leave this to initialize $catid (otherwise a notice is written to the logs) and set $catid = null in your if()-condition if it's empty or doesn't consists of digits