try...catch 的结构
<?php
try {
// perform some task
} catch (Exception $ex) {
// jump to this part
// if an exception occurred
}
你可以使用 isset
<?php
if(isset($_GET['id'])){
$api = new api($_GET["id"]);
echo $api -> processRequest();
}else{
$error = array("error" => $e->getMessage());
echo json_encode($error);
}
?>
奖金示例:
<?php
if(isset($_GET['name'])){
$name = $_GET['name'];
}else{
$name = "Name not set in GET Method";
}
if(isset($_GET['age'])){
$name = $_GET['age'];
}else{
$name = "<br>Age not set in GET Method";
}
echo $name;
echo $age;
?>