Skip to content

Instantly share code, notes, and snippets.

@tayfunerbilen
Created January 17, 2018 21:29
Show Gist options
  • Save tayfunerbilen/20a5e92e4f50b65fa056b1d542931301 to your computer and use it in GitHub Desktop.
Save tayfunerbilen/20a5e92e4f50b65fa056b1d542931301 to your computer and use it in GitHub Desktop.
https://youtu.be/xAuAJI2_5-8 dersi kaynak dosyası
<?php
class Hata extends Exception {
public function printJSON()
{
$arr = [
'mesaj' => $this->message,
'kod' => $this->code,
'satir' => $this->line,
'dosya' => $this->file
];
return json_encode($arr);
}
public function printXML()
{
header('Content-type: text/xml');
$xml = new SimpleXMLElement('<hata/>');
$xml->addChild('mesaj', $this->message);
$xml->addChild('kod', $this->code);
$xml->addChild('satir', $this->line);
$xml->addChild('dosya', $this->file);
return $xml->asXML();
}
}
try {
if (!isset($_GET['id'])){
throw new Hata('ıd parametresi eksik!');
} elseif (empty($_GET['id'])){
throw new Hata('id parametresi boş');
} elseif (!is_numeric($_GET['id'])){
throw new Hata('id değeri sayı değil!');
} else {
echo $_GET['id'];
}
} catch(Hata $e){
echo $e->printJSON();
} finally {
//echo 'finally metodu calıstı';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment