Metin2 EP, Valorant VP dahil tüm oyun ürünlerini en uygun fiyatlarla bulabilir, Item ve Karakterlerinizi hızlıca satabilirsiniz. HEMEN TIKLA!
// $nesne null ise hata almamak için kontrol gerekir.
$sonuc = $nesne !== null ? $nesne->metod() : null;
// Eğer $nesne null ise, $sonuc otomatik olarak null olur. Hata yok!
$sonuc = $nesne?->metod();
class Kullanici {
public function getIsim(): string {
return "Cevat Yılmaz";
}
}
$guncelKullanici = null; // veya new Kullanici();
if ($guncelKullanici !== null) {
$isim = $guncelKullanici->getIsim();
} else {
$isim = "Misafir";
}
// Eğer $guncelKullanici null ise, ->getIsim() hiç çağrılmaz.
// ?? operatörü ise, sol taraf null dönerse sağdaki değeri atar.
$isim = $guncelKullanici?->getIsim() ?? "Misafir";
// $siparis veya $siparis->musteri null olabilir.
if ($siparis !== null && $siparis->musteri !== null) {
$adres = $siparis->musteri->getAdres();
} else {
$adres = null;
}
