PHP Notice: Undefined index although using try\catch
use isset
function to check if the variable is set or not:
if( isset($_GET['id'])){
$api = new api($_GET["id"]);
echo $api -> processRequest();
}
If you want a fast and "dirty" solution, you can use
$api = new api(@$_GET["id"]);
Edit:
Since PHP 7.0 there is a much better and accepted solution: using the null coalescing operator (??). With it you can shorten your code to
$api = new api($_GET["id"] ?? null);
and you don't get a notice because you defined what should happen in the case the variable is not defined.