create account

PHP ile Sınıflar ve Nesne Yönelimli Programlama (OOP) by sedatyildiz

View this thread on: hive.blogpeakd.comecency.com
· @sedatyildiz · (edited)
$15.93
PHP ile Sınıflar ve Nesne Yönelimli Programlama (OOP)
#### Ne Öğreneceğim?
- OOP Nedir?
- OOP Sınıf Yapısı
- OOP Metotları

#### Gereksinimler
- PHP
- Linux

#### Zorluk
- Orta Düzey

![Screenshot_3.png](https://res.cloudinary.com/hpiynhbhq/image/upload/v1517508483/ij9agrve8i9qmjszhb5r.png)

#### Eğitim İçeriği
PHP yazılım dili, tüm programlama dillerinde olduğu üzere nesne yönelimli programlamayı desteklemektedir. Geliştirilmek istenen yazılımı kısaltmak ve dizgesel hale getirmek için çok önemli ve çok sık kullanılan bir yöntemdir.

PHP4 versiyonunda nesne yönelimli yazılımın temelleri oluşturulduğundan eksikler çok fazlaydı ve PHP5 sürümüyle birlikte eksiklikler giderilerek OOP yapısı tekrar oluşturuldu. PHP5 sürümünden itibaren görünürlük, derslik soyutlama, final anahtar sözcüğü, büyülü yöntemler, nesne arayüzleri, nesne kopyalama ve tür dayatma gibi mevzular eklendi.

#### OOP Nedir?
OOP, Object Oriented Programming kelimesinin baş harflerinden oluşan bir programlama yöntemidir. Türkçe karşılığı nesne yönelimli programlama olarak ifade edilebilir.

OOP, birbiri ile alakalı ve dizgesel olarak çalışabilecek kod parçalarını bir arada tutarak, yazılımın bir tüm olarak çalışmasını sağlar. OOP mimarisi ile geliştirilecek sistem parçalara ayrılarak, parçalar arasında illişki kurmaya olanak sağlar.

#### Temel Kavramlar
Nesneler, kendi içerisinde tanımlanan değişken ve ek fonksiyonlardan oluşur. Bir nesne içinde tanımlanan birime **özellik**, nesneye ait fonksiyonlara ise **davranış** yada **metod** adı verilir. Dersliğin üyesi olarak ifade edildiğinde ise bu özellik veya metod olabilir.

#### Sınıf Yapısı
Bir derslik oluşturmak için öncelikle sınıf üyelerinin (özellik ve metotlar) birbiri ile ilişkili olmasına dikkat edilir. Sınıfın yapısı gereği, eğer birbirinden bağımsız özellik ve metotlar kullanırsanız, aslına bakarsanız derslik yazmanın bir anlamı kalmaz. 

```php
<?php
class ilkSinif
{
      #özellik
public $birOzellik;
      #davranis
public function birDavranis()  {
echo 'Davranis Calisti';
             }
}
?>
```

Yukarıdaki sınıf örneğinde, sınıf **ilkSinif** ismiyle oluşturulmuştur. Sınıf içinde **birOzellik** ismiyle değişken ve **birDavranis** ismiyle metod tanımlanmıştır.

#### Sınıf Çağırma (Örnekleme)
Bir dersliği çarpıtmak için **new** anahtar sözcüğü kullanılır. Aslında sınıfların bir çeşit veri türü bulunduğunu düşünürsek, çağırdığımız derslik tipinde bir değişken tanımlıyoruz diyebiliriz.

```php
<?php
$nesne = new ilkSinif();
?>
```

Yukarıda yer edinen kodları dersliğin hemen altına yazarak tanımladığınız sınıftan bir örnek alabilirsiniz. Sınıftan örnek aldıktan sonrasında erişim izni olan özellik ve metotları kullanabiliriz. Derslik özellikleri **$isim** olarak tanımlansa da bu özelliği dışarıdan kullanırken **$nesne->$isim** olarak değil, **$nesne->isim** olarak kullanmanız gerekmektedir.

```php
<?php
$nesne = new ilkSinif();
$nesne->isim = 'Ali';
echo $nesne->utopian();
?>
```

Yukarıdaki örnekte değişkenin içinde tanımlanan isim özelliğine **Ali** değeri yükleniyor ve yine değişken için erişim iznimiz olan **utopian** adlı metodu çalıştırıyoruz.

#### Kurucu ve Yıkıcı Metotlar
Bir derslik örneklendiğinde İlk olarak çalışan metod kurucu (construct) metodlardır. Sınıf üzerinde aslabir işlem yapmasanız dahil, örnek almış olduğunız anda bu metod otomatik olarak çalışır. Aynı şekilde derslik ile olan bağlantınız sonlandığında ise, yıkıcı (destruct) metodu otomatikman çalışır. Kurucu ve yıkısı metotların nasıl tanımlandığını öğrenmek ve bir sınıftan örnek alındığında otomatik olarak çalışmış olduğunı anlamak için aşağıdaki örneği inceleyip çalıştırarak deneyebilirsiniz.

```php
<?php
class ilkSinif
      {
           #kurucu fonksiyon
function __construct() {
echo 'Kurucu fonksiyon çalıştı.';
   }
           #yıkıcı fonksiyon
function __destruct() {
echo 'Yıkıcı fonksiyon çalıştı';
       }
  }
           #nesne örnekleme
$nesne = new ilkSinif();
?>
```

Yukarıdaki örnek dersliği yazıp çalıştırdığınızda kruucu fonksiyon çalışacaktır. Eğer bu sınıf üzerinde işlem gerçekleştirmiş olsaydık, bu işlemler gerçekleştirilecek ve PHP yorumlayıcısı artık dersliğin kullanılmadığını anladığında yıkıcı fonksiyonu çalıştıracaktı.

Kurucu metotlar; çoğu zaman derslik çapırıldığı esnada, sınıfa ilişkin özelliklerin için ilk değerler yüklenir ve lüzumlu görülürse, bazı metotlar tetiklenerek çalıştırılır. Yıkıcı metotlar ise, derslik kullanımını sonlandığinde özelliklerin silinmesi ve yine ihtiyaç halinde bazı metotların çalıştırılması için kullanılabilir.

<br /><hr/><em>Posted on <a href="https://utopian.io/utopian-io/@sedatyildiz/php-ile-siniflar-ve-nesne-yoenelimli-programlama-oop">Utopian.io -  Rewarding Open Source Contributors</a></em><hr/>
👍  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,
properties (23)
authorsedatyildiz
permlinkphp-ile-siniflar-ve-nesne-yoenelimli-programlama-oop
categoryutopian-io
json_metadata{"community":"utopian","app":"utopian/1.0.0","format":"markdown","repository":{"id":1903522,"name":"php-src","full_name":"php/php-src","html_url":"https://github.com/php/php-src","fork":false,"owner":{"login":"php"}},"pullRequests":[],"platform":"github","type":"tutorials","tags":["utopian-io","tr","php","oop"],"users":["sedatyildiz"],"links":["https://res.cloudinary.com/hpiynhbhq/image/upload/v1517508483/ij9agrve8i9qmjszhb5r.png"],"image":["https://res.cloudinary.com/hpiynhbhq/image/upload/v1517508483/ij9agrve8i9qmjszhb5r.png"],"moderator":{"account":"deathwing","time":"2018-02-04T03:45:47.159Z","flagged":false,"reviewed":true,"pending":false}}
created2018-02-01 18:08:18
last_update2018-02-04 03:45:45
depth0
children11
last_payout2018-02-08 18:08:18
cashout_time1969-12-31 23:59:59
total_payout_value11.268 HBD
curator_payout_value4.664 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length4,682
author_reputation4,535,285,897,770
root_title"PHP ile Sınıflar ve Nesne Yönelimli Programlama (OOP)"
beneficiaries
0.
accountutopian.pay
weight2,500
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id34,190,975
net_rshares3,187,678,576,711
author_curate_reward""
vote details (45)
@cheetah ·
Hi! I am a robot. I just upvoted you! I found similar content that readers might be interested in:
https://www.orhanbhr.com/sinif-cagirma-ornekleme-oop/
properties (22)
authorcheetah
permlinkcheetah-re-sedatyildizphp-ile-siniflar-ve-nesne-yoenelimli-programlama-oop
categoryutopian-io
json_metadata""
created2018-02-01 18:08:30
last_update2018-02-01 18:08:30
depth1
children1
last_payout2018-02-08 18:08:30
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length152
author_reputation942,693,160,055,713
root_title"PHP ile Sınıflar ve Nesne Yönelimli Programlama (OOP)"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id34,191,009
net_rshares0
@sedatyildiz · (edited)
Thank you. It's good to see this.
properties (22)
authorsedatyildiz
permlinkre-cheetah-cheetah-re-sedatyildizphp-ile-siniflar-ve-nesne-yoenelimli-programlama-oop-20180201t182441259z
categoryutopian-io
json_metadata{"tags":["utopian-io"],"app":"steemit/0.1"}
created2018-02-01 18:24:42
last_update2018-02-01 19:05:39
depth2
children0
last_payout2018-02-08 18:24:42
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length33
author_reputation4,535,285,897,770
root_title"PHP ile Sınıflar ve Nesne Yönelimli Programlama (OOP)"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id34,194,165
net_rshares0
@deathwing ·
$1.59
Thank you for the contribution. It has been approved.

You can contact us on [Discord](https://discord.gg/uTyJkNm).
**[[utopian-moderator]](https://utopian.io/moderators)**
👍  
properties (23)
authordeathwing
permlinkre-sedatyildiz-php-ile-siniflar-ve-nesne-yoenelimli-programlama-oop-20180204t034551499z
categoryutopian-io
json_metadata{"tags":["utopian-io"],"community":"utopian","app":"utopian/1.0.0"}
created2018-02-04 03:45:48
last_update2018-02-04 03:45:48
depth1
children2
last_payout2018-02-11 03:45:48
cashout_time1969-12-31 23:59:59
total_payout_value1.190 HBD
curator_payout_value0.396 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length172
author_reputation269,077,595,754,009
root_title"PHP ile Sınıflar ve Nesne Yönelimli Programlama (OOP)"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id34,792,129
net_rshares234,316,486,782
author_curate_reward""
vote details (1)
@sedatyildiz ·
Thank you.
properties (22)
authorsedatyildiz
permlinkre-deathwing-re-sedatyildiz-php-ile-siniflar-ve-nesne-yoenelimli-programlama-oop-20180204t050442484z
categoryutopian-io
json_metadata{"tags":["utopian-io"],"app":"steemit/0.1"}
created2018-02-04 05:04:45
last_update2018-02-04 05:04:45
depth2
children0
last_payout2018-02-11 05:04:45
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length10
author_reputation4,535,285,897,770
root_title"PHP ile Sınıflar ve Nesne Yönelimli Programlama (OOP)"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id34,804,381
net_rshares0
@utopian.tip ·
Hey @deathwing, I just gave you a tip for your hard work on moderation. Upvote this comment to support the utopian moderators and increase your future rewards!
properties (22)
authorutopian.tip
permlinkre-re-sedatyildiz-php-ile-siniflar-ve-nesne-yoenelimli-programlama-oop-20180204t034551499z-20180204t060419
categoryutopian-io
json_metadata""
created2018-02-04 06:04:21
last_update2018-02-04 06:04:21
depth2
children0
last_payout2018-02-11 06:04:21
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length159
author_reputation238,310,597,885
root_title"PHP ile Sınıflar ve Nesne Yönelimli Programlama (OOP)"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id34,813,796
net_rshares0
@howo · (edited)
Nevermind
👍  
properties (23)
authorhowo
permlinkre-sedatyildiz-php-ile-siniflar-ve-nesne-yoenelimli-programlama-oop-20180202t172830332z
categoryutopian-io
json_metadata{"tags":["utopian-io"],"community":"utopian","app":"steemit/0.1"}
created2018-02-02 17:28:12
last_update2018-02-02 19:24:21
depth1
children4
last_payout2018-02-09 17:28:12
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length9
author_reputation515,737,941,459,006
root_title"PHP ile Sınıflar ve Nesne Yönelimli Programlama (OOP)"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id34,449,169
net_rshares0
author_curate_reward""
vote details (1)
@remoteman ·
However, the rule has been shared before committing. So it must be valid!
properties (22)
authorremoteman
permlinkre-howo-re-sedatyildiz-php-ile-siniflar-ve-nesne-yoenelimli-programlama-oop-20180202t173422968z
categoryutopian-io
json_metadata{"tags":["utopian-io"],"community":"utopian","app":"utopian/1.0.0"}
created2018-02-02 17:34:30
last_update2018-02-02 17:34:30
depth2
children3
last_payout2018-02-09 17:34:30
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length73
author_reputation260,206,479,074
root_title"PHP ile Sınıflar ve Nesne Yönelimli Programlama (OOP)"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id34,450,292
net_rshares0
@howo ·
No, rule change was 2 days ago : https://steemit.com/utopian-io/@utopian-io/utopian-rules-update-8-dropped-crowdin-support-english-only-and-more

He wrote this yesterday, hence he wrote an article that was not in accordance with the rules when publishing his contribution.
properties (22)
authorhowo
permlinkre-remoteman-re-howo-re-sedatyildiz-php-ile-siniflar-ve-nesne-yoenelimli-programlama-oop-20180202t175145668z
categoryutopian-io
json_metadata{"tags":["utopian-io"],"links":["https://steemit.com/utopian-io/@utopian-io/utopian-rules-update-8-dropped-crowdin-support-english-only-and-more"],"app":"steemit/0.1"}
created2018-02-02 17:51:27
last_update2018-02-02 17:51:27
depth3
children2
last_payout2018-02-09 17:51:27
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length272
author_reputation515,737,941,459,006
root_title"PHP ile Sınıflar ve Nesne Yönelimli Programlama (OOP)"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id34,453,492
net_rshares0
@utopian-io ·
### Hey @sedatyildiz I am @utopian-io. I have just upvoted you!
#### Achievements
- You have less than 500 followers. Just gave you a gift to help you succeed!
- Seems like you contribute quite often. AMAZING!
#### Suggestions
- Contribute more often to get higher and higher rewards. I wish to see you often!
- Work on your followers to increase the votes/rewards. I follow what humans do and my vote is mainly based on that. Good luck!
#### Get Noticed!
- Did you know project owners can manually vote with their own voting power or by voting power delegated to their projects? Ask the project owner to review your contributions!
#### Community-Driven Witness!
I am the first and only Steem Community-Driven Witness. <a href="https://discord.gg/zTrEMqB">Participate on Discord</a>. Lets GROW TOGETHER!
- <a href="https://v2.steemconnect.com/sign/account-witness-vote?witness=utopian-io&approve=1">Vote for my Witness With SteemConnect</a>
- <a href="https://v2.steemconnect.com/sign/account-witness-proxy?proxy=utopian-io&approve=1">Proxy vote to Utopian Witness with SteemConnect</a>
- Or vote/proxy on <a href="https://steemit.com/~witnesses">Steemit Witnesses</a>

[![mooncryption-utopian-witness-gif](https://steemitimages.com/DQmYPUuQRptAqNBCQRwQjKWAqWU3zJkL3RXVUtEKVury8up/mooncryption-s-utopian-io-witness-gif.gif)](https://steemit.com/~witnesses)

**Up-vote this comment to grow my power and help Open Source contributions like this one. Want to chat? Join me on Discord https://discord.gg/Pc8HG9x**
properties (22)
authorutopian-io
permlinkre-sedatyildiz-php-ile-siniflar-ve-nesne-yoenelimli-programlama-oop-20180204t194631058z
categoryutopian-io
json_metadata{"tags":["utopian-io"],"community":"utopian","app":"utopian/1.0.0"}
created2018-02-04 19:46:30
last_update2018-02-04 19:46:30
depth1
children0
last_payout2018-02-11 19:46:30
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length1,509
author_reputation152,955,367,999,756
root_title"PHP ile Sınıflar ve Nesne Yönelimli Programlama (OOP)"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id34,964,236
net_rshares0