When E_NOTICE is set to on, PHP will report undefined index for arrays. I want to suppress this error for $_GET
only. Is there any way to do that other than prepend
The best method is to check for the existence of the array key before you use it each time, using isset
.
So instead of
$cow=(int)$_GET['cow'];
do
if(isset($_GET['cow'])){ $cow=(int)$_GET['cow']; }
That's verbose, however. So, you can wrap this in a function such as
function get($key_name){
return isset($_GET[$key_name])?$_GET[$key_name]:null;
}
and then,
$cow=get('cow');