Untitled
3 years ago in Plain Text
<!DOCTYPE html><html lang="tr-TR" prefix="og: http://ogp.me/ns#" > <head> <meta charset="UTF-8"/> <meta name="viewport" content="width=device-width, initial-scale=1.0"/> <link rel="icon" href="/favicon.ico" type="image/x-icon"/> <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css"/> <title>PHP OOP - Yusuf SEZER</title><meta name="description" content="PHP içerisinde yer alan OOP veya Nesne Yönelimli Programlamada kullanılan anahtar kelimeler örneklerle yer alıyor."/><link rel="canonical" href="https://www.yusufsezer.com.tr/php-oop/"/><meta property="og:title" content="PHP OOP - Yusuf SEZER"/><meta property="og:type" content="article"/><meta property="og:url" content="https://www.yusufsezer.com.tr/php-oop/"/><meta property="og:image" content="https://www.yusufsezer.com.tr/dosyalar/2017/10/php.png"/><meta property="og:image:width" content="450"/><meta property="og:image:height" content="250"/><meta property="og:site_name" content="Yusuf SEZER"/><meta property="fb:admins" content="100010460956162"/><meta property="og:description" content="PHP içerisinde yer alan OOP veya Nesne Yönelimli Programlamada kullanılan anahtar kelimeler örneklerle yer alıyor."/><meta property="article:tag" content="php"/><meta property="article:publisher" content="https://www.facebook.com/yusufsefasezer"/><meta property="article:published_time" content="2017-10-30T15:26:19Z"/><meta property="article:modified_time" content="2019-01-28T05:20:49Z"/><meta name="twitter:card" content="summary_large_image"/><meta name="twitter:site" content="@yusufsefasezer"/><meta name="twitter:domain" content="http://www.yusufsezer.com.tr"/><meta name="twitter:title" content="PHP OOP - Yusuf SEZER"/><meta name="twitter:description" content="PHP içerisinde yer alan OOP veya Nesne Yönelimli Programlamada kullanılan anahtar kelimeler örneklerle yer alıyor."/><meta name="twitter:image" content="https://www.yusufsezer.com.tr/dosyalar/2017/10/php.png"/><meta itemprop="image" content="https://www.yusufsezer.com.tr/dosyalar/2017/10/php.png"/> <meta name="theme-color" content="#343a40"/> <style> body { background-color: #eee; color: #333; -webkit-touch-callout: none; -webkit-user-select: none; -khtml-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none;} a { color: #333; } .content a { color: #0056b3; } .pagination > li > a, .pagination > li > span { color: #333 !Important; } article h2 { font-size: 20px; margin: 15px 0; } article .content p:first-child { color: #888; font-size: 110%; } .list-group a { padding: 5px 10px; border: none; } pre { line-height: normal; position: relative; } pre code { padding: 15px 10px !important; border-left: 4px solid #ff6600; } article { word-wrap: break-word; } article img { max-width: 100%; height: auto; } table, th, td { border: 1px solid #333; border-collapse: collapse; } th, td { padding: 3px; } </style></head><body> <header class="navbar sticky-top navbar-expand-lg navbar-dark" style="background-color: SteelBlue;"> <div class="container"> <a class="navbar-brand" href="/">Yusuf SEZER</a> <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarMain" aria-controls="navbarMain" aria-expanded="false" aria-label="Toggle navigation"> <span class="navbar-toggler-icon"></span> </button> <div class="collapse navbar-collapse" id="navbarMain"> <ul class="navbar-nav mr-auto"> <li class="nav-item active"><a class="nav-link" href="/">Anasayfa</a></li> <li class="nav-item active"><a class="nav-link" href="/hakkimda">Hakkımda</a></li> <li class="nav-item active"><a class="nav-link" href="/iletisim">İletişim</a></li> </ul> <form method="get" class="form-inline my-2 my-lg-0" action="https://www.yusufsezer.com.tr/"> <div class="input-group"> <input type="search" class="form-control" id="s" name="s" placeholder="Arama yap..." /> <span class="input-group-append"> <button type="submit" class="btn btn-success"><svg width="16" height="16" viewBox="0 0 1792 1792" xmlns="http://www.w3.org/2000/svg"><path d="M1216 832q0-185-131.5-316.5t-316.5-131.5-316.5 131.5-131.5 316.5 131.5 316.5 316.5 131.5 316.5-131.5 131.5-316.5zm512 832q0 52-38 90t-90 38q-54 0-90-38l-343-342q-179 124-399 124-143 0-273.5-55.5t-225-150-150-225-55.5-273.5 55.5-273.5 150-225 225-150 273.5-55.5 273.5 55.5 225 150 150 225 55.5 273.5q0 220-124 399l343 343q37 37 37 90z" fill="#ffffff"/></svg></button> </span> </div></form> </div> </div></header><main> <div class="container mt-3"> <div class="row"> <section class="col-md-9"> <nav> <ol class="breadcrumb bg-white border mb-2" itemscope itemtype="https://schema.org/BreadcrumbList"> <li class="breadcrumb-item" itemprop="itemListElement" itemscope itemtype="https://schema.org/ListItem"> <a href="/" title="Yusuf SEZER" itemprop="item name"> Anasayfa <meta itemprop="position" content="1"/> </a> </li> <li class="breadcrumb-item" itemprop="itemListElement" itemscope itemtype="https://schema.org/ListItem"> <a href="/kategori/php/" itemprop="item name" title="PHP"> PHP <meta itemprop="position" content="2"/> </a> </li> <li class="breadcrumb-item active">PHP OOP</li> </ol> </nav> <article class="card mb-2"> <header class="card-header p-2"> <h1 class="h4 m-1"><a href="https://www.yusufsezer.com.tr/php-oop/" title="PHP OOP">PHP OOP</a></h1> </header> <div class="card-body content p-2"><p>PHP içerisinde yer alan OOP veya Nesne Yönelimli Programlamada kullanılan anahtar kelimeler örneklerle yer alıyor.<span id="more-676"></span></p><h2>OOP nedir?</h2><p>OOP (<strong>O</strong>bject <strong>O</strong>riented <strong>P</strong>rogramming) veya NYP (<strong>N</strong>esne <strong>Y</strong>önelimli <strong>P</strong>rogramlama) bir yazılım geliştirme paradigmasıdır.</p><h2>Neden OOP?</h2><p>Yazılımlar geliştikçe karmaşıklaşır ve boyutları artar.</p><p>Karmaşıklık ve boyutun artmasıyla birlikte kodun bakımı, karmaşıklık ve boyuta göre daha fazla artar.</p><p>OOP geliştirilen yazılımın karmaşıklık ve bakım maliyetini azaltmak için kullanılır.</p><p>OOP bakım maliyetini azaltırken, kodun tekrar kullanılabilirliğini, anlaşılabilirliğini de arttırmaktadır.</p><p>Yazılım geliştirme yöntemi OOP destekleyen bir yazılım dili tarafından öğrenildiğinde diğer OOP destekli dilleri öğrenmeyi ve geliştirme yapmayı kolaylaşacaktır.</p><p>OOP tekniği, uzun süredir C++, JAVA ve C# gibi programlama dilleri tarafından başarıyla kullanılmaktadır.</p><p>Yazılım geliştirme sadece kod yazmaktan ibaret değildir.</p><p>Yazılım belirli bir düzene ve geliştirilebilirliğe sahip olmalıdır.</p><p>OOP tekniği içerisinde bulunan soyutlama, arayüz ve kalıtım gibi özelliklerle bu kolay bir şekilde sağlanır.</p><p>PHP OOP desteği sayesinde UML, MVC, HMVC, MVVM, Tasarım desenleri gibi OOP ile geliştirme tekniklerini uygulamayı sağlar.</p><p>Büyük ölçekli yazılımlar ekip halinde yapılır.</p><p>Yazılım içerisinde belirli bir düzen olmadığından kodlar diğer ekip üyeleri tarafından anlaşılmayacaktır.</p><p>Daha kötüsü kodu yazan kişi ekipten ayrıldığında kodu anlamak için ek süreye ihtiyaç duyulacaktır.</p><p>OOP ile geliştirme yapıldığında kodun anlaşılabilirliği artacağından bu gibi sorunlar ortadan kalkacaktır.</p><p>OOP öğrenmenin diğer avantajı PHP ile geliştirilen Zend, Yii, CodeIgniter, Laravel vb. yapıların OOP ile geliştirilmiş olmasıdır.</p><p>OOP tekniği öğrenildiğinde bu yapıların öğrenilmesi kolaylaşacaktır.</p><h2>OOP class</h2><p>OOP ile yazılım geliştirmede kullanılan nesnelere ait özellik ve işlevlerin tanımlandığı yapıya class denir.</p><p>Örnek olarak; kediler ve köpekler bir nesnedir.</p><p>Bu nesnelerin belirli bir özelliği (rengi, göz rengi vb.) ve işlevi (miyavlama, havlama, koşma, yakalama vb.) vardır.</p><p>Bu özellik ve işlevler class yapısı içerisinde tanımlanarak nesnelerin oluşturulması sağlanır.</p><p><strong>class yapısı</strong></p><p>PHP class yapısı temel olarak özellik ve işlevlerden meydana gelir.</p><p>Özellik öznitelik veya alan olarak, işlev ise metot veya yöntem olarak isimlendirilir.</p><p><strong>class örnekleri</strong></p><p>PHP class konusunun daha iyi anlaşılabilmesi için aşağıdaki <span style="text-decoration: underline;">basit class örneklerini</span> incelemek faydalı olacaktır.</p><p>Örnekte insan nesnesine ait bir sınıf tanımlanmıştır.</p><pre><code>&lt;?php
class Kisi {
public $adi;
private $soyadi;
public function __construct($gelenAdi, $gelenSoyadi) {
$this-&gt;adi = $gelenAdi;
$this-&gt;soyadi = $gelenSoyadi;
}
function adiSoyadi() {
return $this-&gt;adi . " " . $this-&gt;soyadi;
}
}
?&gt;</code></pre><p>Örnekte kitap nesnesine ait bir sınıf tanımlanmıştır.</p><pre><code>&lt;?php
class Kitap {
public $kitapAdi;
private $kitapSayfaSayisi;
public function __construct($gelenKitapAdi, $gelenKitapSayfaSayisi) {
$this-&gt;kitapAdi = $gelenKitapAdi;
$this-&gt;kitapSayfaSayisi = $gelenKitapSayfaSayisi;
}
function sayfaSayisi() {
return $this-&gt;kitapSayfaSayisi;
}
}
?&gt;
</code></pre><p><strong>NOT:</strong> Örnekler class yapısı hakkında bilgi edinmek için basit bir şekilde verilmiştir.</p><p><strong>class kullanımı</strong></p><p>Tanımlanmış class yapısını kullanmak için bir örneğinin çıkarılması gerekir.</p><p>Örnekleme <strong>new</strong> anahtar kelimesi ile yapılır.</p><p>Örnekleme sonrasında bir nesne ortaya çıkar.</p><pre><code>&lt;?php
$ben = new Kisi("Yusuf", "SEZER");
?&gt;</code></pre><p>Örnekleme sonrasında sınıf içerisindeki özellik ve işlevlere <strong>-&gt;</strong> ile erişilir.</p><p>İşlevleri/metotları çağırma</p><pre><code>&lt;?php
$ben = new Kisi("Yusuf", "SEZER");
echo $ben-&gt;adiSoyadi();
?&gt;</code></pre><p>Özelliklere/niteliklere erişme</p><pre><code>&lt;?php
$ben = new Kisi("Yusuf", "SEZER");
echo $ben-&gt;adi;
?&gt;</code></pre><p>PHP class yapısının daha iyi anlaşılması için çeşitli örnekler yapıp denemek faydalı olacaktır.</p><h2>OOP özellikler</h2><p>Nesnelerin tanımlandığı sınıf içindeki değişkenlere özellik denir.</p><p>Nesneler çeşitli özelliklere sahip olabilir.</p><p>OOP ile yazılım geliştirmede öğrenci nesnesine ait bir sınıf tanımlandığında öğrenciye ait sıra numarası, adı, soyadı ve bölüm gibi bilgiler bir öğrencinin özelliği olarak ifade edilir.</p><p>Benzer şekilde kedi nesnesine ait bir sınıf tanımlandığında kedinin rengi, boyu, göz rengi vb. bilgiler nesnenin özellikleri olarak tanımlanır.</p><p>Örnekte <strong>Ogrenci</strong> sınıfı ve özellikleri yer almaktadır.</p><pre><code>&lt;?php
class Ogrenci {
private $ogrenciID = 0;
public $ogrenciAdi = "";
public $ogrenciSoyadi = "";
protected $ogrenciBolum = "";
}
?&gt;</code></pre><p>Örnekte <strong>Kedi</strong> sınıfı ve özellikleri yer almaktadır.</p><pre><code>&lt;?php
class Kedi {
public $kediRengi = "";
private $kediBoyu = 0.0;
protected $kediGozRengi = "";
}
?&gt;</code></pre><p>Sınıf içerisindeki özelliklere metotlardan <strong>$this-&gt;ozellikAdi</strong> ile erişilir.</p><p>Özellikler bir OOP kuralı olan public, protected ve private değerleri alan erişim belirleyicilere sahiptir.</p><p>Herhangi bir erişim belirleyici belirtilmediğinde özellik varsayılan olarak <strong>public</strong> erişim belirleyicisine sahip olur.</p><h2>OOP metotlar</h2><p>Nesnelerin tanımlandığı sınıf içindeki fonksiyonlara metot denir.</p><p>Nesneler çeşitli metotlara sahip olabilir.</p><p>OOP ile yazılım geliştirmede öğrenci nesnesine ait bir sınıf tanımlandığında öğrencinin ders eklemesi, çalışması, öğrenci bilgilerinin fonksiyon yardımıyla döndürülmesi metot olarak ifade edilir.</p><p>Benzer şekilde kedi nesnesine ait bir sınıf tanımlandığında kedinin miyavlaması, oyun oynaması, nesnenin metotları olarak tanımlanır.</p><p>Örnekte <strong>Ogrenci</strong> sınıfına özellikler ve metotlar yer almaktadır.</p><pre><code>&lt;?php
class Ogrenci {
private $ogrenciID = 0;
public $ogrenciAdi = "";
public $ogrenciSoyadi = "";
protected $ogrenciBolum = "";
private $dersler = array();
public $durum = "";
public function __construct($oAdi, $oSoyadi, $oBolum) {
$this-&gt;ogrenciAdi = $oAdi;
$this-&gt;ogrenciSoyadi = $oSoyadi;
$this-&gt;ogrenciBolum = $oBolum;
}
protected function dersEkle($dersAdi) {
$this-&gt;dersler[] = $dersAdi;
$this-&gt;dersCalis($dersAdi);
}
private function dersCalis($dersAdi) {
$this-&gt;durum = $dersAdi . " çalışıyor";
}
public function ogrenciBilgileri() {
return $this-&gt;ogrenciAdi . " - " . $this-&gt;ogrenciSoyadi . " - " . $this-&gt;ogrenciBolum;
}
}
$ben = new Ogrenci("Yusuf", "SEZER", "Bilgisayar Mühendisliği");
echo $ben-&gt;ogrenciBilgileri();
?&gt;</code></pre><p>Örnekte <strong>Kedi</strong> sınıfı ve özellikleri yer almaktadır.</p><pre><code>&lt;?php
class Kedi {
public $kediRengi = "";
private $kediBoyu = 0.0;
protected $kediGozRengi = "";
public function miyavla() {
return "Miyav!!!";
}
public function oyunOyna($oyunAdi) {
return "Kedi " . $oyunAdi . " oynuyor";
}
}
$pamuk = new Kedi;
echo $pamuk-&gt;miyavla();
echo "&lt;br /&gt;";
echo $pamuk-&gt;oyunOyna("Top oyunu");
?&gt;</code></pre><p>Sınıf içerisindeki metotlara <strong>$this-&gt;metotAdi</strong> ile erişilir.</p><p>Metotlar bir OOP kuralı olan public, protected ve private değerleri alan erişim belirleyicilere sahiptir.</p><p>Herhangi bir erişim belirleyici belirtilmediğinde metot varsayılan olarak <strong>public</strong> erişim belirleyicisine sahip olur.</p><p>Metotların değer döndürmesi, parametre alması gibi özellikler php fonksiyonlarıyla aynıdır.</p><h2>OOP this</h2><p>PHP ile bir nesne oluşturulduğunda işletim sistemi nesneye ait bilgileri belleğin bir bölümüne yazar.</p><p>Bu bilgilere dışardan nesnenin tanımlandığı değişken ile erişilir.</p><p><strong>Kedi</strong> sınıfındaki metotlara</p><pre><code>$tekir = new Kedi();</code></pre><p>tanımı yapıldığında <strong>$tekir</strong> nesnenin bellek adresini/referansını tutar ve nesneye bu referans ile erişilir.</p><p>Nesnelerin tanımlandığı sınıf içinde, nesne oluşturulmadığından bellek adresi bilinmez, PHP nesne oluşturulurken bellek adresini <strong>$this</strong> anahtar kelimesine atar.</p><p>Böylece nesne içindeki özellik ve metotlara <strong>$this</strong> anahtar kelimesi ile ulaşılır.</p><p><strong>OOP this kullanımı</strong></p><p>Örnekte <strong>Kisi</strong> nesnesine ait bir sınıf tanımlanmıştır.</p><pre><code>&lt;?php
class Kisi {
public $adi;
private $soyadi;
public function __construct($gelenAdi, $gelenSoyadi) {
$this-&gt;adi = $gelenAdi;
$this-&gt;soyadi = $gelenSoyadi;
}
function adiSoyadi() {
return $this-&gt;adi . " " . $this-&gt;soyadi;
}
}
?&gt;</code></pre><p>Örnekte <strong>Urun</strong> nesnesine ait bir sınıf tanımlanmıştır.</p><pre><code>&lt;?php
&lt;?php
class Urun {
public $urunAdi = "";
public $urunFiyat = 0.0;
public $urunKDV = 0.0;
public function __construct($uAdi, $uFiyat, $kdvOrani) {
$this-&gt;urunAdi = $uAdi;
$this-&gt;urunFiyat = $uFiyat; // Özelliklere erişim
$this-&gt;urunKDV = $this-&gt;kdvHesapla($kdvOrani); // Metotlara erişim
}
protected function kdvHesapla($kdvOrani) {
return $this-&gt;urunFiyat * ($kdvOrani / 100);
}
}
$meyve = new Urun("Elma", 15.0, 18.0);
echo "Ürün Adı : ".$meyve-&gt;urunAdi . "&lt;br /&gt;";
echo "Ürün Fiyatı : " . $meyve-&gt;urunFiyat . "&lt;br /&gt;";
echo "Ürün KDV : " . $meyve-&gt;urunKDV . "&lt;br /&gt;";
?&gt;</code></pre><p>OOP this kullanımının daha iyi anlaşılması için çeşitli örnekler yapıp denemek faydalı olacaktır.</p><h2>OOP erişim belirleyiciler</h2><p>Nesne yapısının tanımlandığı sınıf yapısı içindeki özellik ve metotlara nereden erişileceğini belirleyen yapıya erişim belirleyici/gizlilik/görünürlük denir.</p><p>Nesne içindeki bazı özellik ve metotların dışardan erişilemez olması istenebilir.</p><p>Bu durumda özellik veya metodun başına erişim durumuna göre <strong>public</strong>, <strong>protected</strong> ve <strong>private</strong> anahtar kelimeleri yazılır.</p><p>Özellik veya metot <strong>public</strong> ise her yerden erişim sağlanır.</p><p>Örnekte üye nesnesine ait bir sınıf tanımlanmıştır.</p><pre><code>&lt;?php
class Uye {
public $uyeAdi = "";
public $uyeSoyadi = "";
public function __construct($uAdi, $uSoyadi) {
$this-&gt;uyeAdi = $uAdi;
$this-&gt;uyeSoyadi = $uSoyadi;
}
public function adiSoyadi() {
return $this-&gt;uyeAdi . " " . $this-&gt;uyeSoyadi;
}
}
$ben = new Uye("Sefa", "SE");
$ben-&gt;uyeAdi = "Yusuf";
$ben-&gt;uyeSoyadi = "SEZER";
echo $ben-&gt;adiSoyadi();
?&gt;</code></pre><p>Özelliklerin erişim durumu <strong>public</strong> olduğundan dışardan erişim sağlanmıştır.</p><p>Özellik veya metot <strong>protected</strong> ise sınıf içinden ve kalıtım ile türetilen sınıf içinden erişim sağlanır.</p><pre><code>&lt;?php
class Uye {
protected $uyeAdi = "";
protected $uyeSoyadi = "";
public function __construct($uAdi, $uSoyadi) {
$this-&gt;uyeAdi = $uAdi; // protected üyeye erişim
$this-&gt;uyeSoyadi = $uSoyadi; // protected üyeye erişim
}
protected function adiSoyadi() {
return $this-&gt;uyeAdi . " " . $this-&gt;uyeSoyadi;
}
}
$ben = new Uye("Sefa", "SE");
//$ben-&gt;uyeAdi = "Yusuf"; // hata verecektir.
//$ben-&gt;uyeSoyadi = "SEZER"; // hata verecetir.
//echo $ben-&gt;adiSoyadi(); // hata verecektir.
?&gt;</code></pre><p>Özelliklerin erişim durumu <strong>protected</strong> olduğundan dışardan erişim <span style="text-decoration: underline;">sağlanamamıştır</span>.</p><p>Özellik veya metot <strong>private</strong> ise sadece sınıf içinden erişim sağlanır.</p><pre><code>&lt;?php
class Uye {
private $uyeAdi = "";
private $uyeSoyadi = "";
public function __construct($uAdi, $uSoyadi) {
$this-&gt;uyeAdi = $uAdi; // private üyeye erişim
$this-&gt;uyeSoyadi = $uSoyadi; // private üyeye erişim
}
private function adiSoyadi() {
return $this-&gt;uyeAdi . " " . $this-&gt;uyeSoyadi;
}
}
$ben = new Uye("Sefa", "SE");
//$ben-&gt;uyeAdi = "Yusuf"; // hata verecektir.
//$ben-&gt;uyeSoyadi = "SEZER"; // hata verecetir.
//echo $ben-&gt;adiSoyadi(); // hata verecektir.
?&gt;</code></pre><p>Özelliklerin erişim durumu <strong>private</strong> olduğundan dışardan erişim <span style="text-decoration: underline;">sağlanamamıştır</span>.</p><p>Erişim durumu <strong>protected</strong> ve <strong>private</strong> olan özelliklere erişim dolaylı olarak <strong>public</strong> olan metotlar tarafından yapılabilir.</p><pre><code>&lt;?php
class Uye {
protected $uyeAdi = "";
private $uyeSoyadi = "";
public function __construct($uAdi, $uSoyadi) {
$this-&gt;uyeAdi = $uAdi;
$this-&gt;uyeSoyadi = $uSoyadi;
}
public function setAdi($uAdi) {
$this-&gt;uyeAdi = $uAdi; // protected özelliğe dolaylı erişim
}
public function setSoyadi($uSoyadi) {
$this-&gt;uyeSoyadi = $uSoyadi; // private özelliğe dolaylı erişim
}
function adiSoyadi() { // metoda herhangi bir erişim durumu verilmedi?
return $this-&gt;uyeAdi . " " . $this-&gt;uyeSoyadi;
}
}
$ben = new Uye("Sefa", "SE");
$ben-&gt;setAdi("Yusuf");
$ben-&gt;setSoyadi("SEZER");
echo $ben-&gt;adiSoyadi();
?&gt;</code></pre><p>Özellik veya metoda ait herhangi bir erişim durumu belirtilmediğinde varsayılan olarak <strong>public</strong> değerini alır.</p><h2>OOP kurucular ve yıkıcılar</h2><p>Nesne belleğe yüklendiğinde yapılacak işlemler için PHP tarafından otomatik olarak çağrılan kurucu metottan (__construct) faydalanır.</p><p>Nesne bellekten silinirken yapılacak işlemler için PHP tarafından otomatik olarak çağrılan yıkıcı metottan (__destruct) faydalanır.</p><pre><code>&lt;?php
class OrnekNesne {
public function __construct() { // Nesne oluşturulduğunda otomatik çalışacak metot
echo "Nesne belleğe yüklendi. &lt;br /&gt;";
}
public function __destruct() { // Nesne silindiğinde otomatik çalışacak metot
echo "Nesne bellekten silindi.";
}
}
$nesne = new OrnekNesne();
?&gt;</code></pre><p>Örnekte <strong>Uye</strong> nesnesine ait bir sınıf tanımlanmıştır.</p><pre><code>&lt;?php
class Uye {
private $uyeAdi = "";
private $uyeSoyadi = "";
public function __construct($uAdi, $uSoyadi) {
$this-&gt;uyeAdi = $uAdi;
$this-&gt;uyeSoyadi = $uSoyadi;
}
}
$ben = new Uye("Yusuf", "SEZER");
?&gt;</code></pre><p>Dosya işlemlerinin yapıldığı bir sınıf içerisinde kurucu metot ile dosyanın açılması, yıkıcı metot ile de dosyanın kapatılması sağlanabilir.</p><p>Örnekte dosya işlemleri nesnesine ait bir sınıf tanımlanmıştır.</p><pre><code>&lt;?php
class DosyaIslemleri {
private $dosya = null;
private $dosyaAdi = "";
private $dosyaBoyutu = 0;
public function __construct($dAdi) {
$this-&gt;dosyaAdi = $dAdi;
$this-&gt;dosya = fopen($this-&gt;dosyaAdi, "r+");
$this-&gt;dosyaBoyutu = filesize($this-&gt;dosyaAdi);
}
public function dosyaOku() {
return fread($this-&gt;dosya, $this-&gt;dosyaBoyutu);
}
public function __destruct() {
fclose($this-&gt;dosya);
}
}
$metin = new DosyaIslemleri("dosya.txt");
echo $metin-&gt;dosyaOku();
?&gt;</code></pre><p>Kurucu ve yıkıcı metotların kullanımı zorunlu değildir.</p><h2>OOP Sabitler</h2><p>Değerinin sonradan değişmesi istenmeyen değişkenlere sabit denir.</p><p>Örnek olarak PI sayısı, E sayısı, KDV oranı vb. verilebilir.</p><p>PHP ile nesne içinde sabit tanımlamak için <strong>const</strong> anahtar kelimesi kullanılır.</p><pre><code>&lt;?php
class OrnekNesne {
const PI = 3.14;
}
?&gt;</code></pre><p>Sabitin değeri bir işlem sonucu olabilir.</p><pre><code>&lt;?php
class OrnekNesne {
const PI = 2 + 2;
}
?&gt;</code></pre><p>Sabitlere sınıf içerisinden <strong>self</strong> anahtar kelimesi ile erişilir.</p><pre><code>&lt;?php
class OrnekNesne {
const ADI_SOYADI = "Yusuf SEZER";
public function yazdir() {
return self::ADI_SOYADI; // Sabite erişim
}
}
$ben = new OrnekNesne();
echo $ben-&gt;yazdir();
?&gt;</code></pre><p>Sabitlere nesne oluşturmadan kapsama operatörü (::) ile erişilebilir.</p><pre><code>&lt;?php
class OrnekNesne {
const ADI_SOYADI = "Yusuf SEZER";
}
echo OrnekNesne::ADI_SOYADI;
?&gt;</code></pre><p>Sabitlere türetilen sınıf içerisinden <strong>parent</strong> anahtar kelimesi ile erişilir.</p><pre><code>&lt;?php
class OrnekNesne {
const ADI_SOYADI = "Yusuf SEZER";
}
class YeniNesne extends OrnekNesne {
public function yazdir() {
return parent::ADI_SOYADI; // Sabite erişim
}
}
$ben = new YeniNesne();
echo $ben-&gt;yazdir();
?&gt;</code></pre><p>Sabit değişkenler diğer değişkenlerden farklı olarak <strong>$</strong> ile başlamaz.</p><p>Sabit değişken oluşturulduktan sonra değer atanması zorunludur.</p><p>Sabit değişkenlerin adı PHP içinde kullanılan if, while gibi anahtar kelime olamaz.</p><p>Sabit değişkenler erişim belirleyicilere (public, protected, private) sahip olabilir.</p><p>Sabit değişkenlerin adlandırılmasında genellikle büyük karakter kullanılır.</p><h2>OOP static</h2><p>PHP static anahtar kelimesi sadece bir örneğinin olması gereken özellik ve metotlar için kullanılır.</p><p>Örnek olarak <strong>PDO</strong> sınıfına ait <strong>getAvailableDrivers</strong> metodu verilebilir.</p><pre><code>&lt;?php
print_r(PDO::getAvailableDrivers());
?&gt;</code></pre><p><strong>const</strong> anahtar kelimesinden farkı <strong>static</strong> özelliklerin değerinin değişmesi ve $ ile başlamasıdır.</p><p>Sınıf içinde static özellik tanımlamak için <strong>static </strong> anahtar kelimesi kullanılır.</p><pre><code>&lt;?php
class Uye {
static $uyeSayisi = 0;
public static function uyeSayisi() {
}
}
?&gt;</code></pre><p>Sınıf içindeki static özellik ve metotlara <strong>self</strong> anahtar kelimesi ile erişilir.</p><pre><code>&lt;?php
class Uye {
static $uyeSayisi = 0;
public static function uyeSayisi() {
return self::$uyeSayisi; // static özellik
}
public function getBilgi() {
return self::uyeSayisi(); // static metot
}
}
?&gt;</code></pre><p>Sınıf içindeki static özellik ve metotlara nesne oluşturmadan kapsama operatörü (::) ile erişilebilir.</p><pre><code>&lt;?php
error_reporting(E_ALL);
class Uye {
static $uyeSayisi = 0;
public static function uyeSayisi() {
return self::$uyeSayisi;
}
public function getBilgi() {
return self::uyeSayisi();
}
}
echo Uye::$uyeSayisi; // static özellik
echo Uye::uyeSayisi(); // static metot
//echo Uye::getBilgi(); // hata verir.
?&gt;</code></pre><p>Sınıf içindeki static özellik ve metotlara türetilen sınıf içerisinden <strong>parent</strong> anahtar kelimesi ile erişilir.</p><pre><code>&lt;?php
class Uye {
static $uyeSayisi = 0;
public static function uyeSayisi() {
return self::$uyeSayisi;
}
}
class Yonetici extends Uye{
public function uyeSayisiErisim() {
parent::$uyeSayisi++;
return parent::uyeSayisi();
}
}
$admin = new Yonetici();
echo $admin-&gt;uyeSayisiErisim();
?&gt;</code></pre><p>Sınıf içindeki static metottan, static olmayan özellik ve metotlara <strong>$this</strong> veya <strong>self</strong> anahtar kelimesi ile <span style="text-decoration: underline;">erişilemez.</span></p><pre><code>&lt;?php
error_reporting(E_ALL);
class Uye {
static $uyeSayisi = 0;
public static function uyeSayisi() {
return $this-&gt;getBilgi();
}
public function getBilgi() {
return self::$uyeSayisi;
}
}
echo Uye::$uyeSayisi; // static özellik
//echo Uye::uyeSayisi(); // hata verir
?&gt;</code></pre><p>Örnekte <strong>Uye</strong> sınıfı ve <strong>static</strong> özellik ve metot kullanımı ile ilgili örnek yer almaktadır.</p><pre><code>&lt;?php
class Uye {
private $uyeID = 0;
private $uyeAdi = "";
private $uyeSoyadi = "";
private static $uyeSayisi = 0;
public function __construct($uAdi, $uSoyadi) {
$this-&gt;uyeID = self::$uyeSayisi + 1;
$this-&gt;uyeAdi = $uAdi;
$this-&gt;uyeSoyadi = $uSoyadi;
self::$uyeSayisi++;
}
public static function uyeSayisi() {
return self::$uyeSayisi;
}
public function uyeBilgi() {
return $this-&gt;uyeID. " - " . $this-&gt;uyeAdi . " - " . $this-&gt;uyeSoyadi . "&lt;br/&gt;";
}
}
$ben = new Uye("Yusuf", "SEZER");
echo $ben-&gt;uyeBilgi();
$mehmet = new Uye("Mehmet", "SEZER");
echo $mehmet-&gt;uyeBilgi();
$sinan = new Uye("Sinan", "SEZER");
echo $sinan-&gt;uyeBilgi();
echo "Toplam Üye sayısı : " . Uye::uyeSayisi();
?&gt;</code></pre><p>Sınıf içindeki static metot ve özellikler erişim belirleyicilere (public, protected, private) sahip olabilir.</p><h2>OOP kalıtım</h2><p>Detaylı bilgi için <a href="https://www.yusufsezer.com.tr/php-oop-kalitim/" target="_blank" rel="noopener">PHP OOP Kalıtım</a> yazısına bakabilirsiniz.</p><h2>OOP final</h2><p>OOP yöntemi içerisindeki en önemli özellik olan katılım yöntemi bazen istenmeyen bir durum olabilir.</p><p>Bu durumda nesne tanımının yapıldığı sınıfın başına <strong>final</strong> anahtar kelimesi eklenerek sınıfın kalıtım alınması engellenir.</p><pre><code>&lt;?php
final class OrnekNesne {
public function adiYazdir() {
return "Yusuf";
}
}
class YeniNesne extends OrnekNesne { // hata verir.
public function adiYazdir() {
return "Yusuf";
}
}
?&gt;</code></pre><p>Benzer şekilde <strong>final</strong> anahtar kelimesiyle bir metodun tekrar tanımlanması engellenir.</p><pre><code>&lt;?php
class OrnekNesne {
final public function adiYazdir() {
return "Yusuf";
}
}
class YeniNesne extends OrnekNesne {
public function adiYazdir() { // hata verir.
return "Yusuf";
}
}
?&gt;</code></pre><p>PHP içindeki <strong>final</strong> özelliği sayesinde nesne ve metot güvenliği sağlanmış olur.</p><h2>OOP abstract class</h2><p>Detaylı bilgi için <a href="https://www.yusufsezer.com.tr/php-oop-abstract/" target="_blank" rel="noopener">PHP OOP abstract</a> yazısına bakabilirsiniz.</p><h2>OOP interface</h2><p>Detaylı bilgi için <a href="https://www.yusufsezer.com.tr/php-oop-interface/" target="_blank" rel="noopener">PHP OOP interface</a> yazısına bakabilirsiniz.</p><h2>OOP trait</h2><p>Detaylı bilgi için <a href="https://www.yusufsezer.com.tr/php-oop-trait/" target="_blank" rel="noopener">PHP OOP trait</a> yazısına bakabilirsiniz.</p><h2>OOP sihirli metotlar</h2><p>Detaylı bilgi için <a href="https://www.yusufsezer.com.tr/php-oop-sihirli-metotlar/" target="_blank" rel="noopener">PHP OOP Sihirli Metotlar</a> yazısına bakabilirsiniz.</p><h2>OOP anonim sınıflar</h2><p>Herhangi bir isme sahip olmayan sınıflara anonim sınıf denir. Anonim sınıflar OOP class yapısına benzer.</p><p>Ancak anonim sınıflara bir isim verilmediğinden sadece bir defa kullanılır.</p><p>Anonim sınıf oluşturmak içi <strong>new class</strong> yazmak yeterli olacaktır.</p><pre><code>&lt;?php
echo (new class {
private $ogrenciAdi = "Yusuf";
private $ogrenciSoyadi = "SEZER";
public function adiSoyadi() {
return $this-&gt;ogrenciAdi . " " . $this-&gt;ogrenciSoyadi;
}
})-&gt;adiSoyadi();
?&gt;</code></pre><p>Anonim sınıflar genellike değer döndürme işleminde kullanılır.</p><pre><code>&lt;?php
function Hesaplama($s1, $s2) {
return new class($s1, $s1) {
private $sayi1 = 0.0;
private $sayi2 = 0.0;
function __construct($s1, $s2) {
$this-&gt;sayi1 = $s1;
$this-&gt;sayi2 = $s2;
}
public function Topla() {
return $this-&gt;sayi1 + $this-&gt;sayi2;
}
public function Cikar() {
return $this-&gt;sayi1 - $this-&gt;sayi2;
}
public function Carp() {
return $this-&gt;sayi1 * $this-&gt;sayi2;
}
public function Bol() {
return $this-&gt;sayi1 / $this-&gt;sayi2;
}
};
}
echo Hesaplama(10, 20)-&gt;Topla();
echo "&lt;br /&gt;";
echo Hesaplama(10, 20)-&gt;Carp();
?&gt;</code></pre><h2>OOP clone</h2><p>Nesneler temel veri tipleri gibi eşittir (=) ifadesiyle kopyalanamaz.</p><p>Nesneleri kopyalamak için <strong>clone</strong> anahtar kelimesi kullanılır.</p><p>Temel veri tipleri eşittir ifadesiyle eşitlendikten sonra değeri değişse bile eşitlenen değer değişmez.</p><pre><code>&lt;?php
$adi = "Yusuf";
$ben = $adi;
$ben = "Yusuf SEZER";
echo $adi . "&lt;br /&gt;";
echo $ben . "&lt;br /&gt;";
?&gt;</code></pre><p>Ancak nesneler eşittir (=) ifadesiyle eşitlenirse nesneye ait özelliğin değeri değişirse eşitlenen nesnenin değeri de değişir.</p><pre><code>&lt;?php
class Ogrenci {
public $ogrenciAdi = "";
public $ogrenciSoyadi = "";
function __construct($oAdi, $oSoyadi) {
$this-&gt;ogrenciAdi = $oAdi;
$this-&gt;ogrenciSoyadi = $oSoyadi;
}
public function ogrenciBilgileri() {
return $this-&gt;ogrenciAdi . " " . $this-&gt;ogrenciSoyadi;
}
}
$ben = new Ogrenci("Yusuf", "SEZER");
$sinan = $ben;
$sinan-&gt;ogrenciAdi = "Sinan";
$sinan-&gt;ogrenciSoyadi = "SEZER";
echo $sinan-&gt;ogrenciBilgileri(); // Sinan SEZER
echo "&lt;br /&gt;";
echo $ben-&gt;ogrenciBilgileri(); // ??
?&gt;</code></pre><p>Nesneler eşittir (=) ifadesi ile kopyalanamadığından <strong>clone</strong> anahtar kelimesi ile kopyalanır.</p><pre><code>&lt;?php
class Ogrenci {
public $ogrenciAdi = "";
public $ogrenciSoyadi = "";
function __construct($oAdi, $oSoyadi) {
$this-&gt;ogrenciAdi = $oAdi;
$this-&gt;ogrenciSoyadi = $oSoyadi;
}
public function ogrenciBilgileri() {
return $this-&gt;ogrenciAdi . " " . $this-&gt;ogrenciSoyadi;
}
}
$ben = new Ogrenci("Yusuf", "SEZER");
$sinan = clone $ben; // clone ile kopyaladık.
$sinan-&gt;ogrenciAdi = "Sinan";
$sinan-&gt;ogrenciSoyadi = "SEZER";
echo $sinan-&gt;ogrenciBilgileri(); // Sinan SEZER
echo "&lt;br /&gt;";
echo $ben-&gt;ogrenciBilgileri(); // ??
?&gt;</code></pre><p>Nesnelerin değeri değişse bile diğer nesne bundan etkilenmeyecektir.</p><h2>OOP tür dayatma</h2><p>PHP içindeki metotlar veya fonksiyonlar çeşitli parametre değeri alarak işlem yapar.</p><p>Toplama işlemi için parametre olarak alınan iki sayı yerine harf veya cümle yazıldığında PHP uyarı verecek ve istenmeyen bir sonuç üretecektir.</p><pre><code>&lt;?php
function Topla($sayi1, $sayi2) {
return $sayi1 + $sayi2;
}
echo Topla("Yusuf", "SEZER"); // ??
?&gt;</code></pre><p>PHP 7 ile birlikte desteği genişleyen Tür Dayatma özelliği ile daha fazla parametre türü belirtilebilir.</p><pre><code>&lt;?php
function Topla(int $sayi1, int $sayi2) {
return $sayi1 + $sayi2;
}
echo Topla("Yusuf", "SEZER"); // ??
?&gt;</code></pre><p>Girilen parametre türü belirtilenden farklıysa PHP <strong>Fatal error</strong> verip çalışmayı durduracaktır.</p><p>Parametre türü temel veri tipi (int, string, float) olabileceği gibi bir nesne de olabilir.</p><pre><code>&lt;?php
class Ogrenci {
public $ogrenciAdi = "";
public $ogrenciSoyadi = "";
function __construct($oAdi, $oSoyadi) {
$this-&gt;ogrenciAdi = $oAdi;
$this-&gt;ogrenciSoyadi = $oSoyadi;
}
}
function ogrenciBilgileri(Ogrenci $ogr) {
return $ogr-&gt;ogrenciAdi . " " . $ogr-&gt;ogrenciSoyadi;
}
$ben = new Ogrenci("Yusuf", "SEZER");
echo ogrenciBilgileri($ben);
?&gt;</code></pre><p>Tür dayatma özelliği nesne içindeki metotlarda da kullanılabilir.</p><h2>OOP zincirleme metotlar</h2><p>Nesne içindeki metotların <strong>$this</strong> anahtar kelimesi ile nesneyi tekrar referans göstererek nesne içindeki elemanları tekrar kullanmak için geliştirilen bir yöntemdir.</p><p>Yöntem metotların birbirine zincir halkası gibi bağlanmasından dolayı Zincirleme Metot (chaining metod) ismini almıştır.</p><pre><code>&lt;?php
class HesapMakinesi {
private $sonuc = 0;
function __construct($sayi) {
$this-&gt;sonuc = $sayi;
}
public function Toplama($sayi) {
$this-&gt;sonuc += $sayi;
return $this;
}
public function Cikarma($sayi) {
$this-&gt;sonuc -= $sayi;
return $this;
}
public function Carpma($sayi) {
$this-&gt;sonuc *= $sayi;
return $this;
}
public function Bolme($sayi) {
$this-&gt;sonuc /= $sayi;
return $this;
}
public function Goster() {
echo $this-&gt;sonuc;
return $this-&gt;sonuc;
}
}
$hesap = new HesapMakinesi(50);
$hesap-&gt;Toplama(20)-&gt;Cikarma(10)-&gt;Goster();
//$hesap-&gt;Toplama(20)-&gt;Bolme(10)-&gt;Goster();
?&gt;</code></pre><p>Örnekteki tüm metotların geri dönüş değeri olarak <strong>$this</strong> kullandığına dikkat edin.</p><h2>OOP namespace</h2><p>Detaylı bilgi için <a href="https://www.yusufsezer.com.tr/php-oop-namespace/" target="_blank" rel="noopener">PHP OOP namespace</a> yazısına bakabilirsiniz.</p><h2>OOP aşırı yükleme</h2><p>Detaylı bilgi için <a href="https://www.yusufsezer.com.tr/php-oop-asiri-yukleme/" target="_blank" rel="noopener">PHP OOP Aşırı Yükleme</a> yazısına bakabilirsiniz.</p><h2>OOP autoload</h2><p>Detaylı bilgi için <a href="https://www.yusufsezer.com.tr/php-oop-autoload/" target="_blank" rel="noopener">PHP OOP autoload</a> yazısına bakabilirsiniz.</p><p><a href="http://www.yusufsezer.com.tr/php-dersleri/" target="_blank" rel="noopener"><strong>PHP OOP Derslerine buradan ulaşabilirsiniz&#8230;</strong></a></p><p>Hayırlı günler dilerim.</p> <div class="share text-center"> <hr/> <div class="addthis_inline_share_toolbox"></div> </div> </div> </article> <section class="card mb-2"> <div class="card-body content p-3"> <form method="post"> <div class="form-group"> <div class="input-group mb-2"> <div class="input-group-prepend"> <div class="input-group-text"><svg class="bi bi-person" width="1em" height="1em" viewBox="0 0 16 16" fill="currentColor" xmlns="http://www.w3.org/2000/svg"><path fill-rule="evenodd" d="M13 14s1 0 1-1-1-4-6-4-6 3-6 4 1 1 1 1h10zm-9.995-.944v-.002.002zM3.022 13h9.956a.274.274 0 00.014-.002l.008-.002c-.001-.246-.154-.986-.832-1.664C11.516 10.68 10.289 10 8 10c-2.29 0-3.516.68-4.168 1.332-.678.678-.83 1.418-.832 1.664a1.05 1.05 0 00.022.004zm9.974.056v-.002.002zM8 7a2 2 0 100-4 2 2 0 000 4zm3-2a3 3 0 11-6 0 3 3 0 016 0z" clip-rule="evenodd"/></svg></div> </div> <input type="text" class="form-control" name="adisoyadi" placeholder="Adınız & Soyadınız" required="required"/> </div> </div> <div class="form-group"> <div class="input-group mb-2"> <div class="input-group-prepend"> <div class="input-group-text"><svg class="bi bi-envelope-fill" width="1em" height="1em" viewBox="0 0 16 16" fill="currentColor" xmlns="http://www.w3.org/2000/svg"><path d="M.05 3.555L8 8.414l7.95-4.859A2 2 0 0014 2H2A2 2 0 00.05 3.555zM16 4.697l-5.875 3.59L16 11.743V4.697zm-.168 8.108L9.157 8.879 8 9.586l-1.157-.707-6.675 3.926A2 2 0 002 14h12a2 2 0 001.832-1.195zM0 11.743l5.875-3.456L0 4.697v7.046z"/></svg></div> </div> <input type="email" class="form-control" name="eposta" placeholder="Mail adresiniz" required="required"/> </div> </div> <div class="form-group"> <div class="input-group mb-2"> <div class="input-group-prepend"> <div class="input-group-text"><svg class="bi bi-chat" width="1em" height="1em" viewBox="0 0 16 16" fill="currentColor" xmlns="http://www.w3.org/2000/svg"><path fill-rule="evenodd" d="M2.678 11.894a1 1 0 01.287.801 10.97 10.97 0 01-.398 2c1.395-.323 2.247-.697 2.634-.893a1 1 0 01.71-.074A8.06 8.06 0 008 14c3.996 0 7-2.807 7-6 0-3.192-3.004-6-7-6S1 4.808 1 8c0 1.468.617 2.83 1.678 3.894zm-.493 3.905a21.682 21.682 0 01-.713.129c-.2.032-.352-.176-.273-.362a9.68 9.68 0 00.244-.637l.003-.01c.248-.72.45-1.548.524-2.319C.743 11.37 0 9.76 0 8c0-3.866 3.582-7 8-7s8 3.134 8 7-3.582 7-8 7a9.06 9.06 0 01-2.347-.306c-.52.263-1.639.742-3.468 1.105z" clip-rule="evenodd"/></svg></div> </div> <textarea name="mesaj" class="form-control" placeholder="Mesajınız" required="required" rows="3"></textarea> </div> </div> <input type="submit" value="Gönder" class="button btn btn-block text-white" style="background-color: SteelBlue;"/> </form> </div> </section> <hr/> <section> <h3>Bunlara'da bakmalısın!</h3> <nav class="list-group"> <a href="/php-pdo-veri-ekleme/" class="list-group-item-action" title="PHP PDO Veri Ekleme">PHP PDO Veri Ekleme</a> <a href="/php-pdo-veri-cekme/" class="list-group-item-action" title="PHP PDO Veri Çekme">PHP PDO Veri Çekme</a> <a href="/php-curl/" class="list-group-item-action" title="PHP CURL Nedir? Kurulumu ve Kullanımı">PHP CURL Nedir? Kurulumu ve Kullanımı</a> <a href="/php-mysql-veri-cekme/" class="list-group-item-action" title="PHP MySQL Veri Çekme">PHP MySQL Veri Çekme</a> <a href="/php-ip-adresi-alma/" class="list-group-item-action" title="PHP IP Adresi Alma">PHP IP Adresi Alma</a> </nav> </section> </section> <aside class="col-md-3 p-md-0"> <section class="bg-white mb-2 shadow-sm text-center p-2"> <figure class="mb-2"> <img class="rounded-circle" src="/yusuf-sezer.jpg" alt="Yusuf SEZER" title="Yusuf SEZER" width="128" height="128"/> <figcaption class="mt-2"> <h3>Yusuf SEZER</h3> </figcaption> </figure> <a href="https://tr.linkedin.com/in/yusufsefasezer" target="_blank" rel="noreferrer"><svg width="32" height="32" viewBox="0 0 1792 1792" xmlns="http://www.w3.org/2000/svg"><path d="M477 625v991h-330v-991h330zm21-306q1 73-50.5 122t-135.5 49h-2q-82 0-132-49t-50-122q0-74 51.5-122.5t134.5-48.5 133 48.5 51 122.5zm1166 729v568h-329v-530q0-105-40.5-164.5t-126.5-59.5q-63 0-105.5 34.5t-63.5 85.5q-11 30-11 81v553h-329q2-399 2-647t-1-296l-1-48h329v144h-2q20-32 41-56t56.5-52 87-43.5 114.5-15.5q171 0 275 113.5t104 332.5z"/></svg></a> <a href="https://github.com/yusufsefasezer" target="_blank" rel="noreferrer"><svg width="32" height="32" viewBox="0 0 1792 1792" xmlns="http://www.w3.org/2000/svg"><path d="M896 128q209 0 385.5 103t279.5 279.5 103 385.5q0 251-146.5 451.5t-378.5 277.5q-27 5-40-7t-13-30q0-3 .5-76.5t.5-134.5q0-97-52-142 57-6 102.5-18t94-39 81-66.5 53-105 20.5-150.5q0-119-79-206 37-91-8-204-28-9-81 11t-92 44l-38 24q-93-26-192-26t-192 26q-16-11-42.5-27t-83.5-38.5-85-13.5q-45 113-8 204-79 87-79 206 0 85 20.5 150t52.5 105 80.5 67 94 39 102.5 18q-39 36-49 103-21 10-45 15t-57 5-65.5-21.5-55.5-62.5q-19-32-48.5-52t-49.5-24l-20-3q-21 0-29 4.5t-5 11.5 9 14 13 12l7 5q22 10 43.5 38t31.5 51l10 23q13 38 44 61.5t67 30 69.5 7 55.5-3.5l23-4q0 38 .5 88.5t.5 54.5q0 18-13 30t-40 7q-232-77-378.5-277.5t-146.5-451.5q0-209 103-385.5t279.5-279.5 385.5-103zm-477 1103q3-7-7-12-10-3-13 2-3 7 7 12 9 6 13-2zm31 34q7-5-2-16-10-9-16-3-7 5 2 16 10 10 16 3zm30 45q9-7 0-19-8-13-17-6-9 5 0 18t17 7zm42 42q8-8-4-19-12-12-20-3-9 8 4 19 12 12 20 3zm57 25q3-11-13-16-15-4-19 7t13 15q15 6 19-6zm63 5q0-13-17-11-16 0-16 11 0 13 17 11 16 0 16-11zm58-10q-2-11-18-9-16 3-14 15t18 8 14-14z"/></svg></a> <a href="https://twitter.com/yusufsefasezer" target="_blank" rel="noreferrer"><svg width="32" height="32" viewBox="0 0 1792 1792" xmlns="http://www.w3.org/2000/svg"><path d="M1684 408q-67 98-162 167 1 14 1 42 0 130-38 259.5t-115.5 248.5-184.5 210.5-258 146-323 54.5q-271 0-496-145 35 4 78 4 225 0 401-138-105-2-188-64.5t-114-159.5q33 5 61 5 43 0 85-11-112-23-185.5-111.5t-73.5-205.5v-4q68 38 146 41-66-44-105-115t-39-154q0-88 44-163 121 149 294.5 238.5t371.5 99.5q-8-38-8-74 0-134 94.5-228.5t228.5-94.5q140 0 236 102 109-21 205-78-37 115-142 178 93-10 186-50z"/></svg></a> <div class="text-center mt-2"><a class="text-danger" href="http://yusufsezer.com/" target="_blank" rel="noreferrer">www.yusufsezer.com</a></div> </section> <section class="bg-white mb-2 border"> <header class="bg-light p-2"> <h3 class="h5 m-0">İlgini çekebilir</h3> </header> <nav class="list-group"> <a href="/html5-dersleri/" class="list-group-item list-group-item-action" title="HTML5 Dersleri">HTML5</a> <a href="/css3-dersleri/" class="list-group-item list-group-item-action" title="CSS3 Dersleri">CSS3</a> <a href="/rwd/" class="list-group-item list-group-item-action" title="Responsive Web Tasarım Dersleri">Responsive Web Tasarım</a> <a href="/javascript-dersleri/" class="list-group-item list-group-item-action" title="JavaScript Dersleri">JavaScript</a> <a href="/git-dersleri/" class="list-group-item list-group-item-action" title="Git Dersleri">Git</a> <a href="/mongodb-dersleri/" class="list-group-item list-group-item-action" title="MongoDB Dersleri">MongoDB</a> <a href="/node-js-dersleri/" class="list-group-item list-group-item-action" title="Node.js Dersleri">Node.js</a> <a href="/sql-dersleri/" class="list-group-item list-group-item-action" title="SQL Dersleri">SQL</a> <a href="/mysql-dersleri/" class="list-group-item list-group-item-action" title="MySQL Dersleri">MySQL</a> <a href="/oracle-dersleri/" class="list-group-item list-group-item-action" title="Oracle Dersleri">Oracle</a> <a href="/php-dersleri/" class="list-group-item list-group-item-action" title="PHP Dersleri">PHP</a> <a href="/web-servis-dersleri/" class="list-group-item list-group-item-action" title="Web Servis Dersleri">Web Servis</a> <a href="/linux-dersleri/" class="list-group-item list-group-item-action" title="Linux Dersleri">Linux</a> <a href="/programlama-ornekleri/" class="list-group-item list-group-item-action" title="Programlama Örnekleri">Programlama Örnekleri</a> <a href="/cpp-dersleri/" class="list-group-item list-group-item-action" title="C++ Dersleri">C++</a> <a href="/net-dersleri/" class="list-group-item list-group-item-action" title=".NET Dersleri">.NET</a> <a href="/java-dersleri/" class="list-group-item list-group-item-action" title="Java Dersleri">Java</a> </nav> </section> <section class="bg-white mb-2 border"> <header class="bg-light p-2"> <h3 class="h5 m-0">Yeni yazılar</h3> </header> <nav class="list-group"> <a href="/junit/" class="list-group-item list-group-item-action" title="JUnit">JUnit</a><a href="/java-json/" class="list-group-item list-group-item-action" title="Java JSON">Java JSON</a><a href="/java-14/" class="list-group-item list-group-item-action" title="Java 14">Java 14</a><a href="/java-13/" class="list-group-item list-group-item-action" title="Java 13">Java 13</a><a href="/java-12/" class="list-group-item list-group-item-action" title="Java 12">Java 12</a> </nav> </section> <script type="text/javascript">
var sc_project = 11810445;
var sc_invisible = 1;
var sc_security = "d6193d67";
</script> <script type="text/javascript" src="https://www.statcounter.com/counter/counter.js" async></script> <noscript><div class="statcounter"><img class="statcounter" src="//c.statcounter.com/11810445/0/d6193d67/1/" alt="Web Analytics" width="1" height="1"/></div></noscript> </aside> </div> </div></main><footer class="bg-white border-top p-3 text-center"> <div class="container"> <div class="row text-center"> <div class="col-md-6 text-md-left p-2 order-12 order-md-first">Yusuf SEZER <br/> <a href="mailto:yusufsezer@mail.com">yusufsezer@mail.com</a></div> <div class="col-md-6 text-md-right p-2 order-first order-md-12"> <q>İnsanların en hayırlısı insanlara faydalı olanıdır.</q> <br/> Tüm hakları saklıdır. </div> </div> </div></footer> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.13.1/styles/dracula.min.css"/> <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.13.1/highlight.min.js"></script> <script>
document.addEventListener("DOMContentLoaded", baslat);
function baslat(){
var codes = document.querySelectorAll("pre");
var len = codes.length;
var i = 0;
for(i = 0; i < len; i++) {
var btn = document.createElement("button");
btn.type = "button";
btn.className = "btn btn-outline-light btn-sm";
btn.style.position = "absolute";
btn.style.top = "3px";
btn.style.right = "5px";
btn.textContent = "Kopyala";
btn.addEventListener("click", kopyala);
codes[i].insertBefore(btn, codes[i].firstChild);
//codes[i].append(btn);
}
hljs.initHighlightingOnLoad();
}
function kopyala(event){
var code = event.target.parentElement.querySelector("code");
var textarea = document.createElement("textarea");
textarea.textContent = code.textContent;
textarea.style.position = "fixed";
textarea.style.top = 0;
textarea.style.left = 0;
textarea.style.width = "1px";
textarea.style.height = "1px";
textarea.style.padding = 0;
textarea.style.border = "none";
textarea.style.outline = "none";
textarea.style.boxShadow = "none";
textarea.style.background = "transparent";
document.body.appendChild(textarea);
textarea.select();
document.execCommand("copy");
document.body.removeChild(textarea);
this.textContent = "Kopyalandı!";
//var that = this;
//setTimeout(function(){that.textContent = "Kopyala";}, 500);
}
</script> <script src="https://s7.addthis.com/js/300/addthis_widget.js#pubid=ra-56bef9a500e17bd2"></script> <script src="https://code.jquery.com/jquery-3.4.1.slim.min.js"></script> <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.bundle.min.js"></script></body></html>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813