I'm new to PHP and working on script that may have undefined variable and I have two ways to handle this, my question is what is the best way.
Variable $_GET['page'] can be sometimes defined and sometimes undefined.
the first way I check with isset() and if:
if(isset($_GET['page'])){
$sql.=limitrows($_GET['page'],10);
}else{
$sql.=limitrows(1,10);
}
the second way I just write the function and using @ remove the error and handle the isset() inside the function
function limitrows($page=1, $rows=10){
if (isset($page)==false or $page<=0 ){
$page=1;
}
}
$sql.=@limitrows($_GET['page'],10);
the second way make my code much cleaner and I do all the dirty work inside the function but it show error and I have to @.
What is the best way?