<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>Web Geliştirici</title>
	
	<link>http://www.webgelistirici.com</link>
	<description>:: PHP, Kohana, JavaScript, Ajax, XHTML, XML, CSS, MySQL ve diğer web yazılım geliştirme teknolojileri hakkında faydalı bilgi ve teknikler</description>
	<lastBuildDate>Tue, 17 May 2011 14:41:05 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.2</generator>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/webgelistirici" /><feedburner:info uri="webgelistirici" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
		<title>PHP’de Nesne Yönelimli Programlama-13</title>
		<link>http://feedproxy.google.com/~r/webgelistirici/~3/q8iuaf6zZek/phpde-nesne-yonelimli-programlama-13.html</link>
		<comments>http://www.webgelistirici.com/phpde-nesne-yonelimli-programlama-13.html#comments</comments>
		<pubDate>Tue, 17 May 2011 07:14:13 +0000</pubDate>
		<dc:creator>Bülent Yılmaz</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[class]]></category>
		<category><![CDATA[nesne]]></category>
		<category><![CDATA[object]]></category>
		<category><![CDATA[serialize]]></category>
		<category><![CDATA[sınıf]]></category>
		<category><![CDATA[unserialize]]></category>
		<category><![CDATA[__autoload()]]></category>
		<category><![CDATA[__PHP_Incomplete_Class]]></category>
		<category><![CDATA[__sleep]]></category>
		<category><![CDATA[__wakeup]]></category>

		<guid isPermaLink="false">http://www.webgelistirici.com/?p=583</guid>
		<description><![CDATA[Makale içeriğini görmek için lütfen makale başlığına tıklayınız.]]></description>
			<content:encoded><![CDATA[<h2>Nesnelerin Serialize ve Unserialize İşlemleri</h2>
<p>Bilindiği gibi <code>serialize</code> işlemi, nesne ve diziler gibi farklı türdeki veri yapılarının taşınabilir biçimlerini elde etmemize yarıyor. Bu sayede bu tipteki değişkenleri, daha sonra tekrar kullanabilmek için veri tabanı gibi farklı ortamlarda saklayabilir ya da sayfalar arasında parametre olarak taşıyabiliriz.</p>
<p><code>Serialize</code> işlemine tabi tutulmuş bir değişkeni tekrar elde edebilmek için, bu sefer <code>unserialize</code> işlemine tabi tutarız.</p>
<p>Nesneler <code>serialize</code> edilirken nesnenin sadece özellikleri (sabit dışındaki özellikler) <code>serialize</code> edilir, nesnenin yöntemleri <code>serialize</code> işlemine katılmaz. Peki bir nesnenin yöntemlerini <code>serialize/unserialize</code> işlemlerinin ardından tekrar elde etmemiz mümkün değil midir? Bu sorunun cevabını aşağıda inceleyelim.</p>
<p><span id="more-583"></span></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> sinif <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000088;">$ozellik1</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000088;">$ozellik2</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">const</span> SABIT <span style="color: #339933;">=</span> <span style="color: #cc66cc;">20</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> yontem<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'Merhaba'</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Yukarıdaki sınıftan bir nesne türetelim</span>
<span style="color: #000088;">$nesne</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> sinif<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Nesne özelliklerine değer atayalım</span>
<span style="color: #000088;">$nesne</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ozellik1</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">5</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$nesne</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ozellik2</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Oluşturduğumuz nesneyi serialize edelim</span>
<span style="color: #000088;">$nesnenin_serialize_hali</span> <span style="color: #339933;">=</span> <span style="color: #990000;">serialize</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$nesne</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">/*
Bu işlem sonucunda değişkenin değeri aşağıdaki gibi olur
$nesnenin_serialize_hali = 'O:5:&quot;sinif&quot;:2:{s:8:&quot;ozellik1&quot;;i:5;s:8:&quot;ozellik2&quot;;i:10;}'
*/</span></pre></div></div>

<p>Şimdi başka bir PHP dosyası açıp elimizdeki <code>serialize</code> edilmiş metni kullanarak nesneyi tekrar oluşturalım.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// Değişkene nesnenin serialize edilmiş halini atayalım</span>
<span style="color: #000088;">$nesnenin_serialize_hali</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'O:5:&quot;sinif&quot;:2:{s:8:&quot;ozellik1&quot;;i:5;s:8:&quot;ozellik2&quot;;i:10;}'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Unserialize işlemi ile nesneyi tekrar elde edelim</span>
<span style="color: #000088;">$nesne</span> <span style="color: #339933;">=</span> <span style="color: #990000;">unserialize</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$nesnenin_serialize_hali</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Nesne içeriğini ekranda gösterelim</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;pre&gt;'</span><span style="color: #339933;">.</span><span style="color: #990000;">print_r</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$nesne</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">TRUE</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;/pre&gt;'</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">/*
Çıktı:
&nbsp;
__PHP_Incomplete_Class Object
(
    [__PHP_Incomplete_Class_Name] =&gt; sinif
    [ozellik1] =&gt; 5
    [ozellik2] =&gt; 10
)
// Görüldüğü gibi nesnede en başta bulunan SABIT ve yontem() üyeleri artık bulunmuyor 
*/</span>
&nbsp;
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$nesne</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ozellik1</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Çıktı: 5</span>
&nbsp;
<span style="color: #000088;">$nesne</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">yontem</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// HATA; nesnede şu anda böyle bir yöntem bulunmuyor</span></pre></div></div>

<p>Görüldüğü gibi &#8220;<code>__PHP_Incomplete_Class</code>&#8221; adlı bir sınıfdan bir nesne elde etmiş olduk. Bu sınıf PHP&#8217;nin öntanımlı bir sınıfıdır. Oluşturulan nesnenin sınıf tanımı o anda bulunamadı ise kullanılır. Sayfamızda şu anda &#8220;<code>sinif</code>&#8221; isimli bir sınıf tanımı mevcut olmadığı için bu öntanımlı sınıftan bir nesne elde etmiş olduk. </p>
<p>Görüldüğü gibi elde edilen nesnenin özelliklerinden birisi, nesnenin ilk türetilmiş olduğu sınıfın adını (&#8220;<code>sinif</code>&#8220;) tutuyor. Ayrıca nesnenin başlangıçta sahip olduğu &#8220;<code>SABIT</code>&#8221; isimli sabiti ve &#8220;<code>yontem()</code>&#8221; adlı yöntemi tekrar elde edemedik.</p>
<p>Şimdi de nesnenin ilk türetildiği sınıfın tanımını sayfamıza ekleyip ondan sonra <code>unserialize</code> yapıp nesnemizi tekrar elde edelim ve arada farka bakalım.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// Önce sınıf tanımını sayfaya ekleyelim</span>
<span style="color: #000000; font-weight: bold;">class</span> sinif <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000088;">$ozellik1</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000088;">$ozellik2</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">const</span> SABIT <span style="color: #339933;">=</span> <span style="color: #cc66cc;">20</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> yontem<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'Merhaba'</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Değişkene nesnenin serialize edilmiş halini atayalım</span>
<span style="color: #000088;">$nesnenin_serialize_hali</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'O:5:&quot;sinif&quot;:2:{s:8:&quot;ozellik1&quot;;i:5;s:8:&quot;ozellik2&quot;;i:10;}'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Unserialize işlemi ile nesneyi tekrar elde edelim</span>
<span style="color: #000088;">$nesne</span> <span style="color: #339933;">=</span> <span style="color: #990000;">unserialize</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$nesnenin_serialize_hali</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Nesne içeriğini ekranda gösterelim</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;pre&gt;'</span><span style="color: #339933;">.</span><span style="color: #990000;">print_r</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$nesne</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">TRUE</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;/pre&gt;'</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">/*
Çıktı:
&nbsp;
sinif Object
(
    [ozellik1] =&gt; 5
    [ozellik2] =&gt; 10
)
*/</span>
&nbsp;
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$nesne</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ozellik1</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Çıktı: 5</span>
&nbsp;
<span style="color: #b1b100;">echo</span> sinif<span style="color: #339933;">::</span><span style="color: #004000;">SABIT</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Çıktı: 20</span>
&nbsp;
<span style="color: #000088;">$nesne</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">yontem</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Çıktı: Merhaba</span></pre></div></div>

<p>Görüldüğü gibi bu sefer olması gerektiği gibi &#8220;<code>sinif</code>&#8221; sınıfından bir nesne elde ettik ve nesnenin sabit ve yöntemi tekrar kullanılabilir oldu.</p>
<p>Son olarak eğer <code>__autoload()</code> fonksiyonu ile sınıflarımızı otomatik olarak yükletiyorsak, <code>unserialize()</code> işlemini yaptığımız yere sınıf tanımını yazmamıza gerek kalmayacaktı. Şimdi bununla ilgili bir örnek yapalım. Ayrıca bu örnekte nesneyi <code>serialize</code> işlemine tuttuğumuzda otomatik olarak çalışan <code>__sleep()</code> sihirli yöntemini ve <code>unserialize()</code> ile nesneyi yeniden oluştururken otomatik olarak çalışan <code>__wakeup()</code> sihirli yöntemini de kullanalım.</p>
<p>Öncelikle sınıfımızı <code>__autoload()</code> ile otomatik olarak yükletebilmek için sınıf tanımımızı &#8220;<code>sinif.php</code>&#8221; adında harici bir dosyaya taşıyalım.</p>
<p><strong>Harici dosya:</strong> <code>sinif.php</code></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> sinif <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000088;">$ozellik1</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000088;">$ozellik2</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">const</span> SABIT <span style="color: #339933;">=</span> <span style="color: #cc66cc;">20</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> yontem<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'Merhaba&lt;br/&gt;'</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// Bu sihirli yöntem, nesne serialize işlemine tabi tutulduğunda devreye girer</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __sleep<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'Serialize işlemi gerçekleşti&lt;br/&gt;'</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">// Serialize işlemine dahil edilmesi gereken özellik isimlerini dizi olarak döndürmemiz gerek</span>
        <span style="color: #b1b100;">return</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'ozellik1'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'ozellik2'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// Bu sihirli yöntem, unserialize işlemi sonucu nesne tekrar elde edildiğinde devreye girer</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __wakeup<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'Unserialize işlemi gerçekleşti&lt;br/&gt;'</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Şimdi yeni bir PHP dosyasında aşağıdaki işlemleri yapalım.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> __autoload<span style="color: #009900;">&#40;</span><span style="color: #000088;">$sinif</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">include</span> <span style="color: #000088;">$sinif</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'.php'</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// &quot;sinif.php&quot; dosyası otomatik dahil edilecek</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000088;">$nesne</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> sinif<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$nesne</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ozellik1</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">5</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$nesne</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ozellik2</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$x</span> <span style="color: #339933;">=</span> <span style="color: #990000;">serialize</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$nesne</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">/*
__sleep() sihirli yöntemi devreye girer
$x = 'O:5:&quot;sinif&quot;:2:{s:8:&quot;ozellik1&quot;;i:5;s:8:&quot;ozellik2&quot;;i:10;}' olarak atanır
&nbsp;
Çıktı: Serialize işlemi gerçekleşti
*/</span>
&nbsp;
<span style="color: #000088;">$nesne</span> <span style="color: #339933;">=</span> <span style="color: #990000;">unserialize</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$x</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">/*
__wakeup() sihirli yöntemi devreye girer
&nbsp;
Çıktı: Unserialize işlemi gerçekleşti
*/</span>
&nbsp;
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;pre&gt;'</span><span style="color: #339933;">.</span><span style="color: #990000;">print_r</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$nesne</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">TRUE</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;/pre&gt;'</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">/*
Çıktı:
&nbsp;
sinif Object
(
    [ozellik1] =&gt; 5
    [ozellik2] =&gt; 10
)
*/</span>
&nbsp;
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$nesne</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ozellik1</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;br/&gt;'</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Çıktı: 5</span>
&nbsp;
<span style="color: #000088;">$nesne</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">yontem</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Çıktı: Merhaba</span>
&nbsp;
<span style="color: #b1b100;">echo</span> sinif<span style="color: #339933;">::</span><span style="color: #004000;">SABIT</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Çıktı: 20</span></pre></div></div>

<img src="http://feeds.feedburner.com/~r/webgelistirici/~4/q8iuaf6zZek" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.webgelistirici.com/phpde-nesne-yonelimli-programlama-13.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.webgelistirici.com/phpde-nesne-yonelimli-programlama-13.html</feedburner:origLink></item>
		<item>
		<title>PHP’de Nesne Yönelimli Programlama-12</title>
		<link>http://feedproxy.google.com/~r/webgelistirici/~3/9hZ0IZq4FiI/phpde-nesne-yonelimli-programlama-12.html</link>
		<comments>http://www.webgelistirici.com/phpde-nesne-yonelimli-programlama-12.html#comments</comments>
		<pubDate>Mon, 16 May 2011 12:25:02 +0000</pubDate>
		<dc:creator>Bülent Yılmaz</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[aşırı yükleme]]></category>
		<category><![CDATA[class]]></category>
		<category><![CDATA[nesne]]></category>
		<category><![CDATA[object]]></category>
		<category><![CDATA[overloading]]></category>
		<category><![CDATA[sınıf]]></category>

		<guid isPermaLink="false">http://www.webgelistirici.com/?p=569</guid>
		<description><![CDATA[Makale içeriğini görmek için lütfen makale başlığına tıklayınız.]]></description>
			<content:encoded><![CDATA[<h2>Nesne Yöntemlerinin Aşırı Yüklenmesi (Method Overloading)</h2>
<p>PHP&#8217;de nesne yöntemlerinin aşırı yüklenmesi, yöntemlerin farklı sayıda parametre alarak çalışabilmesini ifade eder. Bunun için bir yöntemin farklı sayıda parametre ile çalışabilen birden fazla kopyası tanımlanır.</p>
<p>Nesne yöntemlerinin aşırı yüklenmesi için, <code>__call()</code> veya <code>__callStatic()</code> sihirli yöntemlerinden faydalanılır.</p>
<p><span id="more-569"></span></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> sinif <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> yontem1<span style="color: #009900;">&#40;</span><span style="color: #000088;">$x</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #666666; font-style: italic;">// &quot;yontem&quot; isimli yöntem, 1 parametre ile çağrılırsa bu yöntem çalışacak</span>
&nbsp;
        <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$x</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;br /&gt;'</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> yontem2<span style="color: #009900;">&#40;</span><span style="color: #000088;">$x</span><span style="color: #339933;">,</span> <span style="color: #000088;">$y</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #666666; font-style: italic;">// &quot;yontem&quot; isimli yöntem, 2 parametre ile çağrılırsa bu yöntem çalışacak</span>
&nbsp;
        <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$x</span><span style="color: #339933;">.</span><span style="color: #0000ff;">' - '</span><span style="color: #339933;">.</span><span style="color: #000088;">$y</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __call<span style="color: #009900;">&#40;</span><span style="color: #000088;">$tanimsiz_yontem_adi</span><span style="color: #339933;">,</span> <span style="color: #000088;">$parametreler</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$tanimsiz_yontem_adi</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'yontem'</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$parametre_sayisi</span> <span style="color: #339933;">=</span> <span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$parametreler</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
            <span style="color: #b1b100;">switch</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$parametre_sayisi</span><span style="color: #009900;">&#41;</span>
            <span style="color: #009900;">&#123;</span>
                <span style="color: #b1b100;">case</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">:</span>
                    <span style="color: #666666; font-style: italic;">// &quot;yontem&quot; isimli yöntem, 1 parametre ile çağrılırsa &quot;yontem1&quot; yöntemi çalıştırılsın</span>
                    <span style="color: #000088;">$calistirilacak_yontem_adi</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'yontem1'</span><span style="color: #339933;">;</span>
                    <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
                <span style="color: #b1b100;">case</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">:</span>
                    <span style="color: #666666; font-style: italic;">// &quot;yontem&quot; isimli yöntem, 2 parametre ile çağrılırsa &quot;yontem2&quot; yöntemi çalıştırılsın</span>
                    <span style="color: #000088;">$calistirilacak_yontem_adi</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'yontem2'</span><span style="color: #339933;">;</span>
                    <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
                <span style="color: #b1b100;">default</span><span style="color: #339933;">:</span>
                    <span style="color: #b1b100;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> Exception<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Eksik veya fazla parametre girdiniz!'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
&nbsp;
            <span style="color: #666666; font-style: italic;">// Nesnemizin ilgili yöntemini parametrelerimizi de göndererek çalıştıralım</span>
            <span style="color: #990000;">call_user_func_array</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">,</span> <span style="color: #000088;">$calistirilacak_yontem_adi</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$parametreler</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
            <span style="color: #666666; font-style: italic;">// Ek bilgi:</span>
            <span style="color: #666666; font-style: italic;">// call_user_func_array() fonksiyonu, bir nesnenin bir yöntemini çalıştırmaya yarar</span>
            <span style="color: #666666; font-style: italic;">// Kullanımı: call_user_func_array(array($nesne, $calistirilacak_yontem_adi), $parametre_dizisi)</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #b1b100;">else</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #b1b100;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> Exception<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Tanımsız bir yöntem çağırdınız!'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000088;">$nesne</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> sinif<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$nesne</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">yontem</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">3</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// __call() devreye girer, yontem1() çalıştırılır</span>
<span style="color: #000088;">$nesne</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">yontem</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">3</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">5</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// __call() devreye girer, yontem2() çalıştırılır</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Not: Olmayan static tanımlı bir yöntem çağrılmış olsaydı,  __call() yerine __callStatic() sihirli yöntemi devreye girecekti</span></pre></div></div>

<p>Şimdi de farklı parametre sayısına göre farklı kurucu yöntemin çalıştığı bir örnek yapalım. Nesne oluşturulurken kaç parametre gönderilirse, ilgili kurucu yöntem devreye girsin.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> sinif <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __construct<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #666666; font-style: italic;">// Nesne oluşturulurken gönderilen parametre sayısı</span>
        <span style="color: #000088;">$parametre_sayisi</span> <span style="color: #339933;">=</span> <span style="color: #990000;">func_num_args</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">// Nesne oluşturulurken gönderilen parametrelerden oluşan dizi</span>
        <span style="color: #000088;">$parametreler</span> <span style="color: #339933;">=</span> <span style="color: #990000;">func_get_args</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">// Nesne oluşturulurken, sınıf kaç parametre ile çağrıldı ise ilgili kurucu yöntem çalıştırılsın</span>
        <span style="color: #b1b100;">switch</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$parametre_sayisi</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #b1b100;">case</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">:</span> <span style="color: #666666; font-style: italic;">// Parametresiz kullanılmışsa</span>
                <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>__call<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'__construct0'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
            <span style="color: #b1b100;">case</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">:</span> <span style="color: #666666; font-style: italic;">// 1 parametre ile kullanılmışsa</span>
                <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>__call<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'__construct1'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$parametreler</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
            <span style="color: #b1b100;">case</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">:</span> <span style="color: #666666; font-style: italic;">// 2 parametre ile kullanılmışsa</span>
                <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>__call<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'__construct2'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$parametreler</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
            <span style="color: #b1b100;">default</span><span style="color: #339933;">:</span> <span style="color: #666666; font-style: italic;">// Diğer durumlarda</span>
                <span style="color: #b1b100;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> Exception<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Parametre sayısı hatalı!'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __construct0<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #666666; font-style: italic;">// Birinci yapılandırıcı yöntemimiz</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'__construct0 çalıştı&lt;br /&gt;'</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __construct1<span style="color: #009900;">&#40;</span><span style="color: #000088;">$x</span><span style="color: #009900;">&#41;</span> <span style="color: #666666; font-style: italic;">// İkinci yapılandırıcı yöntemimiz</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'__construct1 çalıştı&lt;br /&gt;'</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __construct2<span style="color: #009900;">&#40;</span><span style="color: #000088;">$x</span><span style="color: #339933;">,</span> <span style="color: #000088;">$y</span><span style="color: #009900;">&#41;</span> <span style="color: #666666; font-style: italic;">// Üçüncü yapılandırıcı yöntemimiz</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'__construct2 çalıştı'</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __call<span style="color: #009900;">&#40;</span><span style="color: #000088;">$tanimsiz_yontem_adi</span><span style="color: #339933;">,</span> <span style="color: #000088;">$parametreler</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$tanimsiz_yontem_adi</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">11</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'__construct'</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #990000;">call_user_func_array</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">,</span> <span style="color: #000088;">$tanimsiz_yontem_adi</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$parametreler</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #b1b100;">else</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #b1b100;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> Exception<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Tanımsız bir yöntem çağırdınız!'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000088;">$nesne0</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> sinif<span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// __construct0 çalıştırılır</span>
<span style="color: #000088;">$nesne1</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> sinif<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">3</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// __construct1 çalıştırılır</span>
<span style="color: #000088;">$nesne2</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> sinif<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">3</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">5</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// __construct2 çalıştırılır</span></pre></div></div>

<img src="http://feeds.feedburner.com/~r/webgelistirici/~4/9hZ0IZq4FiI" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.webgelistirici.com/phpde-nesne-yonelimli-programlama-12.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.webgelistirici.com/phpde-nesne-yonelimli-programlama-12.html</feedburner:origLink></item>
		<item>
		<title>PHP’de Nesne Yönelimli Programlama-11</title>
		<link>http://feedproxy.google.com/~r/webgelistirici/~3/fH-AY-LnTx8/phpde-nesne-yonelimli-programlama-11.html</link>
		<comments>http://www.webgelistirici.com/phpde-nesne-yonelimli-programlama-11.html#comments</comments>
		<pubDate>Mon, 16 May 2011 12:05:16 +0000</pubDate>
		<dc:creator>Bülent Yılmaz</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[aşırı yükleme]]></category>
		<category><![CDATA[class]]></category>
		<category><![CDATA[nesne]]></category>
		<category><![CDATA[object]]></category>
		<category><![CDATA[overloading]]></category>
		<category><![CDATA[sınıf]]></category>

		<guid isPermaLink="false">http://www.webgelistirici.com/?p=559</guid>
		<description><![CDATA[Makale içeriğini görmek için lütfen makale başlığına tıklayınız.]]></description>
			<content:encoded><![CDATA[<h2>Nesne Özelliklerinin Aşırı Yüklenmesi (Property Overloading)</h2>
<p>PHP&#8217;de nesne özelliklerinin aşırı yüklenmesi, bir nesnenin olmayan bir özelliğinin çalışma zamanında dinamik olarak oluşturulmasını ifade eder.</p>
<p>Olmayan özelliklerin çalışma esnasında oluşturulabilmesi için <code>__set()</code>, <code>__get()</code>, <code>__isset()</code> ve <code>__unset()</code> sihirli yöntemlerinden faydalanılır.</p>
<p><span id="more-559"></span></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> sinif <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// Olmayan özellikleri çalışma esnasında dizi tipindeki bu özellikte tutacağız</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000088;">$dinamik_ozellikler</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __set<span style="color: #009900;">&#40;</span><span style="color: #000088;">$ozellik</span><span style="color: #339933;">,</span> <span style="color: #000088;">$de</span>ğer<span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #666666; font-style: italic;">// Olmayan bir özelliğe değer atanmaya çalışılırsa bu yöntem devreye girer</span>
&nbsp;
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">dinamik_ozellikler</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$ozellik</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$de</span>ğer<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __get<span style="color: #009900;">&#40;</span><span style="color: #000088;">$ozellik</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #666666; font-style: italic;">// Olmayan bir özelliğin değeri alınmaya çalışılırsa bu yöntem devreye girer</span>
&nbsp;
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">dinamik_ozellikler</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$ozellik</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">dinamik_ozellikler</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$ozellik</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __isset<span style="color: #009900;">&#40;</span><span style="color: #000088;">$ozellik</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #666666; font-style: italic;">// Olmayan bir özelliğin varlığı kontrol edilirse bu yöntem devreye girer</span>
&nbsp;
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">dinamik_ozellikler</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$ozellik</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">TRUE</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #b1b100;">else</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">FALSE</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __unset<span style="color: #009900;">&#40;</span><span style="color: #000088;">$ozellik</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #666666; font-style: italic;">// Olmayan bir özellik yokedilmeye çalışılırsa bu yöntem devreye girer</span>
&nbsp;
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">dinamik_ozellikler</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$ozellik</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #990000;">unset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">dinamik_ozellikler</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$ozellik</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000088;">$nesne</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> sinif<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$nesne</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">x</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">5</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// __set() devreye girer</span>
&nbsp;
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$nesne</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">x</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// __get() devreye girer</span>
&nbsp;
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span> <span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$nesne</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">x</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #666666; font-style: italic;">// __isset() devreye girer</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #990000;">unset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$nesne</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">x</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// __unset() devreye girer</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<img src="http://feeds.feedburner.com/~r/webgelistirici/~4/fH-AY-LnTx8" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.webgelistirici.com/phpde-nesne-yonelimli-programlama-11.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.webgelistirici.com/phpde-nesne-yonelimli-programlama-11.html</feedburner:origLink></item>
		<item>
		<title>PHP’de Nesne Yönelimli Programlama-10</title>
		<link>http://feedproxy.google.com/~r/webgelistirici/~3/xLEBVupEtdM/phpde-nesne-yonelimli-programlama-10.html</link>
		<comments>http://www.webgelistirici.com/phpde-nesne-yonelimli-programlama-10.html#comments</comments>
		<pubDate>Fri, 13 May 2011 11:27:13 +0000</pubDate>
		<dc:creator>Bülent Yılmaz</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[class]]></category>
		<category><![CDATA[implements]]></category>
		<category><![CDATA[isim alanı]]></category>
		<category><![CDATA[namespace]]></category>
		<category><![CDATA[nesne]]></category>
		<category><![CDATA[object]]></category>
		<category><![CDATA[sınıf]]></category>

		<guid isPermaLink="false">http://www.webgelistirici.com/?p=529</guid>
		<description><![CDATA[Makale içeriğini görmek için lütfen makale başlığına tıklayınız.]]></description>
			<content:encoded><![CDATA[<h2>İsim Alanı (Namespace)</h2>
<p>Özellikle büyük projelerde çok sayıda sınıf ve kütüphanenin birlikte kullanılması sonucu isim çakışmalarının olma ihtimali ortaya çıkar. Bunun önüne geçmek için genellikle framework yapılarında çok uzun sınıf isimleri verilir.</p>
<p>PHP 5.3 ile beraber bu tür durumlar göz önünde bulundurularak <strong>isim alanı</strong> (<em>namespace</em>) olanağı geldi. İsim alanı sayesinde farklı isim alanları altında olmak koşuluyla aynı isimde sınıflar kullanabiliriz. İsim alanı bize birbirleriyle ilişkili sınıfları, aynı isim etrafında organize etmemizi sağlar. Sınıfı kullanırken bilgisayardaki dosya sistemindeki mantıkla benzer şekilde &#8220;<code>alan\sinif</code>&#8221; biçiminde kullanılır. Görüldüğü gibi ayırıcı karakter olarak &#8220;<code>\</code>&#8221; karakteri kullanılmaktadır.</p>
<p><span id="more-529"></span></p>
<p>İsim alanı tanımlamak için <code>namespace</code> deyiminden faydalanılır. İsim alanının tanımlandığı dosyada, namespace bloğunun dışında başka bir PHP kodu bulunamaz, aksi halde ölümcül hata (<em>fatal error</em>) oluşacaktır.</p>
<p>Bir dosya içinde birden fazla isim alanı aynı anda tanımlanabilir. Benzer şekilde bir isim alanı ile ilgili sınıflar ayrı dosyalarda da tanımlanabilir. Yani birden fazla dosyada aynı isim alanı ile ilgili tanımlamalar yapmak mümkündür.</p>
<p>Bir isim alanına &#8220;<code>use</code>&#8221; deyimi ile, başka bir isim alanını veya başka bir isim alanında tanımlı bir sınıfı dahil edebiliriz. Ayrıca istersek dahil ettiğimiz isim alanı veya sınıfa &#8220;<code>as</code>&#8221; deyimi ile takma ad verebiliriz.</p>
<p><strong>Harici dosya:</strong> <code>isim_alani.php</code></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// namespace bloğu dışında PHP kodu bulunamaz</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">namespace</span> alan1 <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">class</span> sinif <span style="color: #009900;">&#123;</span>
&nbsp;
       <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> yontem<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
       <span style="color: #009900;">&#123;</span>
               <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'İsim alanı : '</span><span style="color: #339933;">.</span>__NAMESPACE__<span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;br/&gt;'</span><span style="color: #339933;">;</span>
               <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'Sınıf : '</span><span style="color: #339933;">.</span><span style="color: #009900; font-weight: bold;">__CLASS__</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;br/&gt;'</span><span style="color: #339933;">;</span>
               <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'Yöntem : '</span><span style="color: #339933;">.</span><span style="color: #009900; font-weight: bold;">__METHOD__</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;br/&gt;&lt;br/&gt;'</span><span style="color: #339933;">;</span>
       <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// namespace bloğu dışında PHP kodu bulunamaz</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">namespace</span> alan2 <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// Durum 1 : İsim alanına başka bir isim alanını dahil ediyoruz</span>
    <span style="color: #000000; font-weight: bold;">use</span> alan1<span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// (Durum-1)</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// Durum 2 : İsim alanına başka bir isim alanındaki bir sınıfı dahil ediyoruz</span>
    <span style="color: #666666; font-style: italic;">//use alan1\sinif2; // (Durum-2)</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// Durum 3 : İsim alanına dahil ettiğimiz sınıflara takma ad tanımlayabiliyoruz</span>
    <span style="color: #666666; font-style: italic;">//use alan1\sinif2 as _sinif2; // (Durum-3)</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">class</span> sinif <span style="color: #009900;">&#123;</span>
&nbsp;
       <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> yontem<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
       <span style="color: #009900;">&#123;</span>
           <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'İsim alanı : '</span><span style="color: #339933;">.</span>__NAMESPACE__<span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;br/&gt;'</span><span style="color: #339933;">;</span>
           <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'Sınıf : '</span><span style="color: #339933;">.</span><span style="color: #009900; font-weight: bold;">__CLASS__</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;br/&gt;'</span><span style="color: #339933;">;</span>
           <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'Yöntem : '</span><span style="color: #339933;">.</span><span style="color: #009900; font-weight: bold;">__METHOD__</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;br/&gt;&lt;br/&gt;'</span><span style="color: #339933;">;</span>
       <span style="color: #009900;">&#125;</span>
&nbsp;
       <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> yontem2<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
       <span style="color: #009900;">&#123;</span>
           <span style="color: #000088;">$nesne</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> alan1\sinif2<span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// (Durum-1)</span>
&nbsp;
           <span style="color: #666666; font-style: italic;">//$nesne = new sinif2; // (Durum-2)</span>
&nbsp;
           <span style="color: #666666; font-style: italic;">//$nesne = new _sinif2; // (Durum-3)</span>
&nbsp;
           <span style="color: #000088;">$nesne</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">yontem</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
       <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// namespace bloğu dışında PHP kodu bulunamaz</span></pre></div></div>

<p>Bu harici dosyayı kullanarak örneğimizi yapalım.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">include</span> <span style="color: #0000ff;">'isim_alani.php'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$nesne1</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> alan1\sinif<span style="color: #339933;">;</span>
<span style="color: #000088;">$nesne2</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> alan2\sinif<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$nesne1</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">yontem</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">/*
Çıktı:
&nbsp;
İsim alanı : alan1
Sınıf : alan1\sinif
Yöntem : alan1\sinif::yontem
*/</span>
&nbsp;
<span style="color: #000088;">$nesne2</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">yontem</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">/*
Çıktı:
&nbsp;
İsim alanı : alan2
Sınıf : alan2\sinif
Yöntem : alan2\sinif::yontem
*/</span>
&nbsp;
<span style="color: #000088;">$nesne2</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">yontem2</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">/*
Çıktı:
&nbsp;
İsim alanı : alan1
Sınıf : alan1\sinif2
Yöntem : alan1\sinif2::yontem
*/</span></pre></div></div>

<img src="http://feeds.feedburner.com/~r/webgelistirici/~4/xLEBVupEtdM" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.webgelistirici.com/phpde-nesne-yonelimli-programlama-10.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.webgelistirici.com/phpde-nesne-yonelimli-programlama-10.html</feedburner:origLink></item>
		<item>
		<title>PHP’de Nesne Yönelimli Programlama-9</title>
		<link>http://feedproxy.google.com/~r/webgelistirici/~3/vl72Q6Magw8/phpde-nesne-yonelimli-programlama-9.html</link>
		<comments>http://www.webgelistirici.com/phpde-nesne-yonelimli-programlama-9.html#comments</comments>
		<pubDate>Fri, 13 May 2011 11:11:45 +0000</pubDate>
		<dc:creator>Bülent Yılmaz</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[arayüz]]></category>
		<category><![CDATA[class]]></category>
		<category><![CDATA[interface]]></category>
		<category><![CDATA[nesne]]></category>
		<category><![CDATA[object]]></category>
		<category><![CDATA[sınıf]]></category>

		<guid isPermaLink="false">http://www.webgelistirici.com/?p=526</guid>
		<description><![CDATA[Makale içeriğini görmek için lütfen makale başlığına tıklayınız.]]></description>
			<content:encoded><![CDATA[<h2>Arayüz (Interface)</h2>
<p>Arayüz, bir sınıfta bulunması gereken yöntemlerin tanımlandığı bir yapıdır. Arayüzde sadece hangi yöntemlerin bulunacağı belirtilir ancak yöntemlerin nasıl gerçekleştirileceği belirtilmez. Yani yöntemlerin sadece tanımı yapılır, gövdeleri yazılmaz. Yöntemlerin gövdeleri arayüzü kullanan sınıflar içinden yapılır. Böylece bir arayüzü kullanan her sınıf, arayüzdeki yöntemlerin farklı şekilde iş yapmasını sağlayabilir.</p>
<p>Arayüzdeki tüm yöntemlerin <code>public</code> olarak tanımlanması gerekmektedir. Arayüzde tanımlanmış olan tüm yöntemlerin, o arayüzü kullanan sınıfın içinde gövdelerinin tanımlanması zorunludur. Aksi halde ölümcül hata (<em>fatal error</em>) verilecektir.</p>
<p>Bir sınıfın bir arayüzü kullanabilmesi için &#8220;<code>implements</code>&#8221; deyiminden faydalanılır. Aralarına virgül konarak bir sınıfın aynı anda birden fazla arayüzü kullanmasını sağlayabiliriz.</p>
<p><span id="more-526"></span></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">interface</span> arayuz1 <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> yontem1<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Public olmak zorunda</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">interface</span> arayuz2 <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> yontem2<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Public olmak zorunda</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> sinif implements arayuz1<span style="color: #339933;">,</span> arayuz2 <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> yontem1<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #666666; font-style: italic;">// Tanımlanmak zorunda, yoksa hata verir</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'Selam '</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> yontem2<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #666666; font-style: italic;">// Tanımlanmak zorunda, yoksa hata verir</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'Merhaba '</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> yontem3<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'Dünya'</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000088;">$nesne</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> sinif<span style="color: #339933;">;</span>
<span style="color: #000088;">$nesne</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">yontem1</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$nesne</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">yontem2</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$nesne</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">yontem3</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Çıktı: Selam Merhaba Dünya</span></pre></div></div>

<img src="http://feeds.feedburner.com/~r/webgelistirici/~4/vl72Q6Magw8" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.webgelistirici.com/phpde-nesne-yonelimli-programlama-9.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.webgelistirici.com/phpde-nesne-yonelimli-programlama-9.html</feedburner:origLink></item>
		<item>
		<title>PHP’de Nesne Yönelimli Programlama-8</title>
		<link>http://feedproxy.google.com/~r/webgelistirici/~3/prQNlNHyl6A/phpde-nesne-yonelimli-programlama-8.html</link>
		<comments>http://www.webgelistirici.com/phpde-nesne-yonelimli-programlama-8.html#comments</comments>
		<pubDate>Fri, 13 May 2011 11:00:21 +0000</pubDate>
		<dc:creator>Bülent Yılmaz</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[abstract]]></category>
		<category><![CDATA[class]]></category>
		<category><![CDATA[object]]></category>
		<category><![CDATA[sınıf]]></category>
		<category><![CDATA[soyut]]></category>

		<guid isPermaLink="false">http://www.webgelistirici.com/?p=520</guid>
		<description><![CDATA[Makale içeriğini görmek için lütfen makale başlığına tıklayınız.]]></description>
			<content:encoded><![CDATA[<h2>Soyut Sınıf (Abstract Class)</h2>
<p>Soyut sınıf, her koşulda geçerli olabilecek genel özellik ve yöntemleri tanımladığımız bir sınıf şablonudur. Soyut sınıf kullanılarak sadece sınıf kalıtılabilir, nesne türetilmez. Bir soyut sınıftan nesne türetilmeye çalışılırsa hata oluşucaktır.</p>
<p>Soyut sınıflar içinde soyut yöntemler tanımlanabilir. Bu durumda soyut yöntemin sadece tanım satırı yazılır, gövde bloğu yazılmaz. Soyut yöntemin detayları türetilen sınıfta yazılır. Soyut yöntemlerin türetilen sınıfta gövdelerinin tanımlanması zorunludur. Yazılmazsa hata oluşacaktır.</p>
<p><span id="more-520"></span></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">abstract <span style="color: #000000; font-weight: bold;">class</span> soyut_sinif <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000088;">$x</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Selam '</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> abstract <span style="color: #000000; font-weight: bold;">function</span> yontem1<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Soyut yöntem; sadece tanım satırı var, gövdesi yok</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> yontem2<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'Merhaba '</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> sinif <span style="color: #000000; font-weight: bold;">extends</span> soyut_sinif <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> yontem1<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #666666; font-style: italic;">// Tanımlanmak zorunda, yoksa hata verir</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">x</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> yontem3<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'Dünya'</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// $nesne = new soyut_sinif; // HATA; soyut sınıftan nesne türetilemez</span>
&nbsp;
<span style="color: #000088;">$nesne</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> sinif<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$nesne</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">yontem1</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$nesne</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">yontem2</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$nesne</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">yontem3</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Çıktı: Selam Merhaba Dünya</span></pre></div></div>

<p>Şimdi de gerçek hayattan bir örnek verelim:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">abstract <span style="color: #000000; font-weight: bold;">class</span> canli <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// Bu sınıf, bütün canlılara özgü en genel özellik ve eylemleri içeriyor</span>
    <span style="color: #666666; font-style: italic;">// &quot;canli&quot; sınıfı tek başına bir anlam ifade etmiyor</span>
    <span style="color: #666666; font-style: italic;">// Kendisinden başka sınıflar türetildiğinde anlam ifade ediyor</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000088;">$yas</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Her canlının bir yaşı vardır</span>
    <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000088;">$yasama_durumu</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">TRUE</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Her canlı bir gün ölür</span>
&nbsp;
     <span style="color: #666666; font-style: italic;">// Her canlı beslenir ancak beslenme şekilleri birbirinden farklıdır</span>
    <span style="color: #000000; font-weight: bold;">public</span> abstract <span style="color: #000000; font-weight: bold;">function</span> beslen<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> hayvan <span style="color: #000000; font-weight: bold;">extends</span> canli <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000088;">$tur</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000088;">$cins</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> beslen<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #666666; font-style: italic;">// Hayvanın beslenmesi insandan farklıdır</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> insan <span style="color: #000000; font-weight: bold;">extends</span> canli <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000088;">$cinsiyet</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000088;">$meslek</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> beslen<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #666666; font-style: italic;">// İnsanın beslenmesi hayvandan farklıdır</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

<img src="http://feeds.feedburner.com/~r/webgelistirici/~4/prQNlNHyl6A" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.webgelistirici.com/phpde-nesne-yonelimli-programlama-8.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.webgelistirici.com/phpde-nesne-yonelimli-programlama-8.html</feedburner:origLink></item>
		<item>
		<title>PHP’de Nesne Yönelimli Programlama-7</title>
		<link>http://feedproxy.google.com/~r/webgelistirici/~3/fUUm8PfSFhI/phpde-nesne-yonelimli-programlama-7.html</link>
		<comments>http://www.webgelistirici.com/phpde-nesne-yonelimli-programlama-7.html#comments</comments>
		<pubDate>Tue, 10 May 2011 10:08:11 +0000</pubDate>
		<dc:creator>Bülent Yılmaz</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[class]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[object]]></category>
		<category><![CDATA[sınıf]]></category>
		<category><![CDATA[veritabanı]]></category>

		<guid isPermaLink="false">http://www.webgelistirici.com/?p=439</guid>
		<description><![CDATA[Makale içeriğini görmek için lütfen makale başlığına tıklayınız.]]></description>
			<content:encoded><![CDATA[<h2>Veritabanı İşlemleri İçin Basit Bir Sınıf Yazalım</h2>
<p>Temel mantığı anlatabilmek adına, filtreleme ve güvenlik önlemlerini gözardı ederek temel veritabanı işlemlerinin yapılabileceği son derece sade bir sınıf yazalım. Temel anlaşıldıktan sonra bu sınıf daha da geliştirilebilir.</p>
<p>&#8220;<code><strong>test</strong></code>&#8221; isimli bir veritabanımız ve bu veritabanı içinde &#8220;<code><strong>kisi</strong></code>&#8221; adında bir tablomuz olsun. Bu tablonun içeriği aşağıdaki gibi olsun;</p>
<div style="text-align:center;"><a href="http://www.webgelistirici.com/wp-content/uploads/1305021426712.png"><img src="http://www.webgelistirici.com/wp-content/uploads/1305021426712.png" alt="" title="Tablo" width="199" height="100" class="aligncenter size-full wp-image-448" /></a></div>
<p>Şimdi sınıfımızı yazıp <code><strong>"vt.sinif.php"</strong></code> adıyla kaydedelim. Bu dosyanın içeriği aşağıda görülmektedir.</p>
<p><span id="more-439"></span></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #009933; font-style: italic;">/**
 * vt.sinif.php
 * 
 * Veritabanı işlemleri için basit bir sınıf
 *
 * @author Bülent YILMAZ
 */</span>
<span style="color: #000000; font-weight: bold;">class</span> vt <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$sunucu</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Veritabanı sunucusunun adresini tutacak</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$kullanici_adi</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$sifre</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$veritabani</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Kullanılacak veritabanının adını tutacak</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$vt_baglanti</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// mysql_connect() fonksiyonundan dönen değeri tutacak</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$vt_kaynak</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// mysql_query() fonksiyonundan dönen değeri tutacak</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$sonuc</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// SELECT sorgularından dönen nesne dizisini tutacak</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     * Kurucu yöntem. Burada ilklendirme işlemleri yapılır.
     *
     * @param string $sunucu
     * @param string $kullanici_adi
     * @param string $sifre
     * @param string $veritabani
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __construct<span style="color: #009900;">&#40;</span><span style="color: #000088;">$sunucu</span><span style="color: #339933;">,</span> <span style="color: #000088;">$kullanici_adi</span><span style="color: #339933;">,</span> <span style="color: #000088;">$sifre</span><span style="color: #339933;">,</span> <span style="color: #000088;">$veritabani</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">sunucu</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$sunucu</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">kullanici_adi</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$kullanici_adi</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">sifre</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$sifre</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">veritabani</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$veritabani</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">vt_baglanti</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">NULL</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">vt_kaynak</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">NULL</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">sonuc</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     * Veritabanı bağlantısı yapılır.
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> baglan<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #666666; font-style: italic;">// Veritabanı sunucusuna bağlan</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">vt_baglanti</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_connect</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">sunucu</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">kullanici_adi</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">sifre</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">// Veritabanı sunucusu ile bağlantı gerçekleşti ise istenen veritabanını seçili hale getir</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">is_resource</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">vt_baglanti</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #990000;">mysql_select_db</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">veritabani</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     * Sorgu işletilir.
     *
     * @param string $sorgu
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> sorgu_islet<span style="color: #009900;">&#40;</span><span style="color: #000088;">$sorgu</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">vt_kaynak</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sorgu</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">vt_baglanti</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     * SELECT sorguları için nesne dizisi döndürülür
     * 
     * @return array
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> kayitlari_getir<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">vt_kaynak</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #990000;">mysql_num_rows</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">vt_kaynak</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$sorgu_fo</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_fetch_object</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">vt_kaynak</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
            <span style="color: #009900;">&#123;</span>
                <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">sonuc</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$sorgu_fo</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Her kayıt bir nesne olarak dizide toplanır</span>
            <span style="color: #009900;">&#125;</span>
&nbsp;
            <span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">sonuc</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Nesne dizisini döndür</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     *  Yıkıcı yöntem. Burada sonlandırma işlemleri yapılır.
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __destruct<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">is_resource</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">vt_baglanti</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #990000;">mysql_close</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">vt_baglanti</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Veritabanı bağlantısını sonlandır</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #990000;">unset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">sonuc</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Nesne dizisi oluşturulmuş ise yoket</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Veritabanı sınıfımızı kullanarak birkaç örnek yapalım.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">include</span> <span style="color: #0000ff;">'vt.sinif.php'</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Veritabanı sınıfımızın tanımlı olduğu dosyayı dahil edelim</span>
&nbsp;
<span style="color: #000088;">$vt</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> vt<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'127.0.0.1'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'root'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'123'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'test'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Veritabanı nesnemizi tanımlayalım</span>
&nbsp;
<span style="color: #000088;">$vt</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">baglan</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Veritabanı bağlantısını kuralım</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// SELECT sorgusu</span>
<span style="color: #000088;">$vt</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">sorgu_islet</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot; SELECT * FROM kisi &quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$vt</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">kayitlari_getir</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$kayit</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$kayit</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ad</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;br /&gt;'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #666666; font-style: italic;">/*
Çıktı:
&nbsp;
Ahmet
Mehmet
Hasan
*/</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// UPDATE sorgusu</span>
<span style="color: #000088;">$vt</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">sorgu_islet</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot; UPDATE kisi SET ad = 'Ziya' WHERE id = 1 &quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// DELETE sorgusu</span>
<span style="color: #000088;">$vt</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">sorgu_islet</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot; DELETE FROM kisi WHERE id = 1 &quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<img src="http://feeds.feedburner.com/~r/webgelistirici/~4/fUUm8PfSFhI" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.webgelistirici.com/phpde-nesne-yonelimli-programlama-7.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.webgelistirici.com/phpde-nesne-yonelimli-programlama-7.html</feedburner:origLink></item>
		<item>
		<title>PHP’de Nesne Yönelimli Programlama-6</title>
		<link>http://feedproxy.google.com/~r/webgelistirici/~3/vG5I4sQBOP4/phpde-nesne-yonelimli-programlama-6.html</link>
		<comments>http://www.webgelistirici.com/phpde-nesne-yonelimli-programlama-6.html#comments</comments>
		<pubDate>Fri, 06 May 2011 13:10:14 +0000</pubDate>
		<dc:creator>Bülent Yılmaz</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[class]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[object]]></category>
		<category><![CDATA[pattern]]></category>
		<category><![CDATA[singleton]]></category>

		<guid isPermaLink="false">http://www.webgelistirici.com/?p=403</guid>
		<description><![CDATA[Makale içeriğini görmek için lütfen makale başlığına tıklayınız.]]></description>
			<content:encoded><![CDATA[<h2>Tekilleştirme Tasarım Kalıbı (Singleton Design Pattern)</h2>
<p>Tekilleştirme tasarım kalıbı, veritabanı bağlantısı gibi, çalışma anında bir sınıfın sadece tek bir örneğinin yeterli olduğu durumlarda kullanılır. Tek bir nesne <code>static</code> olarak çağrılarak bellekte tutulur ve her ihtiyaç duyulduğunda nesneyi yeniden oluşturmak yerine bellekte daha önce oluşturulmuş olan nesne kullanılır. Bu da bize performans ve bellek kazancı olarak geri döner. </p>
<p>Tekilleştirme tasarım kalıbının özelliği gereği bellekte yalnızca bir kez oluşturulur ve ikinci bir oluşturma girişimine izin verilmez. Tekil nesne bellekte tutulduğu için <code>static</code> olarak tanımlanma zorunluluğu vardır.</p>
<p><span id="more-403"></span></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> sinif <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">private</span> static <span style="color: #000088;">$nesne</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Bellekte sınıfın tek örneğini tutacak olan sınıf özelliği</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Kurucu yöntemler normalde public olarak tanımlanır.</span>
	<span style="color: #666666; font-style: italic;">// Tekilleştirme tasarım kalıbının özelliği gereği burada kurucu metod private olarak tanımlanıyor.</span>
	<span style="color: #666666; font-style: italic;">// Burada amaç, nesnenin &quot;new&quot; işleci ile doğrudan oluşturulmasını engellemektir.</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">function</span> __construct<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Static olarak tanımlıyoruz ki; nesne oluşmamış olsa bile bu yöntemi çağırabilelim.</span>
	<span style="color: #000000; font-weight: bold;">public</span> static <span style="color: #000000; font-weight: bold;">function</span> singleton<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    	<span style="color: #009900;">&#123;</span>
           	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span> <span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #000088;">$nesne</span> instanceof <span style="color: #000000; font-weight: bold;">self</span><span style="color: #009900;">&#41;</span> <span style="color: #666666; font-style: italic;">// Sınıfın daha önceden oluşturulmuş bir örneği (yani nesne) yoksa</span>
           	<span style="color: #009900;">&#123;</span>
                   	<span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #000088;">$nesne</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Nesneyi oluşturalım ve sınıfımızın tek örneğini tutan özelliğimize atayalım</span>
           	<span style="color: #009900;">&#125;</span>
           	<span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #000088;">$nesne</span><span style="color: #339933;">;</span>
    	<span style="color: #009900;">&#125;</span>
&nbsp;
    	<span style="color: #666666; font-style: italic;">// Örnek bir yöntem tanımlayalım</span>
    	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> yontem<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    	<span style="color: #009900;">&#123;</span>
    	    	<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'Merhaba'</span><span style="color: #339933;">;</span>
    	<span style="color: #009900;">&#125;</span>
&nbsp;
    	<span style="color: #666666; font-style: italic;">// &quot;__clone&quot; yöntemini kullanarak dışarıdan bu sınıfın çoğaltılmasını engelliyoruz.</span>
    	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __clone<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    	<span style="color: #009900;">&#123;</span>
          	<span style="color: #990000;">trigger_error</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Nesne çoğaltılamaz!'</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">E_USER_ERROR</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    	<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Kurucu yöntem <code>private</code> olarak tanımlı olduğu için nesne doğrudan oluşturulamaz.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$nesne</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> sinif<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Ölümcül hata (fatal error) oluşur</span></pre></div></div>

<p>Nesneyi oluşturup örnek bir yöntemini çalıştırmak istersek;</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$nesne</span> <span style="color: #339933;">=</span> sinif<span style="color: #339933;">::</span><span style="color: #004000;">singleton</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$nesne</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">yontem</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Çıktı: Merhaba</span>
<span style="color: #666666; font-style: italic;">// veya</span>
sinif<span style="color: #339933;">::</span><span style="color: #004000;">singleton</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">yontem</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Çıktı: Merhaba</span></pre></div></div>

<p>Nesne çoğaltılamaz.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$nesne2</span> <span style="color: #339933;">=</span> clone<span style="color: #009900;">&#40;</span><span style="color: #000088;">$nesne</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Ölümcül hata (fatal error) oluşur</span></pre></div></div>

<img src="http://feeds.feedburner.com/~r/webgelistirici/~4/vG5I4sQBOP4" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.webgelistirici.com/phpde-nesne-yonelimli-programlama-6.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.webgelistirici.com/phpde-nesne-yonelimli-programlama-6.html</feedburner:origLink></item>
		<item>
		<title>PHP’de Nesne Yönelimli Programlama-5</title>
		<link>http://feedproxy.google.com/~r/webgelistirici/~3/02o4lvlSKG0/phpde-nesne-yonelimli-programlama-5.html</link>
		<comments>http://www.webgelistirici.com/phpde-nesne-yonelimli-programlama-5.html#comments</comments>
		<pubDate>Wed, 04 May 2011 12:14:46 +0000</pubDate>
		<dc:creator>Bülent Yılmaz</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[class]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[factory]]></category>
		<category><![CDATA[object]]></category>
		<category><![CDATA[pattern]]></category>

		<guid isPermaLink="false">http://www.webgelistirici.com/?p=399</guid>
		<description><![CDATA[Makale içeriğini görmek için lütfen makale başlığına tıklayınız.]]></description>
			<content:encoded><![CDATA[<h2>Üreteç Tasarım Kalıbı (Factory Design Pattern)</h2>
<p>Üreteç tasarım kalıbı, nesnelerin çalışma anında üretilmesini sağlar. Parametre olarak sınıf ismini alır, tanımlı olduğu dosyayı otomatik olarak sayfaya dahil eder ve nesneyi oluşturup geriye döndürür.</p>
<p>Tüm nesneleri, ayrı ayrı üretmek yerine tek bir sınıfın <code>static</code> bir yöntemi üzerinden üretmek içi bu tasarım kalıbı kullanılabilir. Böylece herbir sınıfı sayfaya yüklemek için, tanımlı oldukları dosyaları <code>include</code> ile tek tek sayfaya yazmaktan kurtuluruz. Ayrıca sınıflarımızın yolu değiştiğinde, <code>include</code> ile sınıf dosyasını yüklediğimiz her yerde yolu düzeltmek yerine, üreteç yöntemi içinde yolu düzelterek kolayca bu işin üstesinden gelebiliriz.</p>
<p><span id="more-399"></span></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> nesne_uret <span style="color: #009900;">&#123;</span>
&nbsp;
   <span style="color: #666666; font-style: italic;">// Tüm sınıflarımızın içinde tanımlı olduğu dizinin yolunu tutacak sabit</span>
   <span style="color: #000000; font-weight: bold;">const</span> DIZIN_YOLU <span style="color: #339933;">=</span> <span style="color: #0000ff;">'./siniflar/'</span><span style="color: #339933;">;</span>
&nbsp;
   <span style="color: #000000; font-weight: bold;">public</span> static <span style="color: #000000; font-weight: bold;">function</span> factory<span style="color: #009900;">&#40;</span><span style="color: #000088;">$sinif_adi</span><span style="color: #009900;">&#41;</span> <span style="color: #666666; font-style: italic;">/* static olmak zorunda */</span>
   <span style="color: #009900;">&#123;</span>
       try
       <span style="color: #009900;">&#123;</span>
           <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">file_exists</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #004000;">DIZIN_YOLU</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$sinif_adi</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'.php'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
           <span style="color: #009900;">&#123;</span>
               <span style="color: #666666; font-style: italic;">// Sınıfın tanımlı olduğu dosyayı dahil edelim </span>
               <span style="color: #b1b100;">include_once</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #004000;">DIZIN_YOLU</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$sinif_adi</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
               <span style="color: #666666; font-style: italic;">// Nesneyi üretip geriye döndürelim </span>
               <span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #000088;">$sinif_adi</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
           <span style="color: #009900;">&#125;</span>
           <span style="color: #b1b100;">else</span>
           <span style="color: #009900;">&#123;</span>
               <span style="color: #b1b100;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> Exception<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Sınıf Bulunamadı!'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
           <span style="color: #009900;">&#125;</span>            
       <span style="color: #009900;">&#125;</span>
       catch <span style="color: #009900;">&#40;</span>Exception <span style="color: #000088;">$hata</span><span style="color: #009900;">&#41;</span>
       <span style="color: #009900;">&#123;</span>
           <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;pre&gt;'</span> <span style="color: #339933;">.</span> <span style="color: #990000;">print_r</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$hata</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">TRUE</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&lt;/pre&gt;'</span><span style="color: #339933;">;</span>
       <span style="color: #009900;">&#125;</span>
   <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// &quot;sinif&quot; isimli sınıf, &quot;./siniflar/sinif.php&quot; dosyası içinde tanımlı</span>
<span style="color: #000088;">$nesne</span> <span style="color: #339933;">=</span> nesne_uret<span style="color: #339933;">::</span><span style="color: #004000;">factory</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'sinif'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$nesne</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">yontem</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Çıktı: 5</span></pre></div></div>

<p><code>"<strong>sinif.php</strong>"</code> içeriği;</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> sinif <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$x</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">5</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> yontem<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
           <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">x</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

<img src="http://feeds.feedburner.com/~r/webgelistirici/~4/02o4lvlSKG0" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.webgelistirici.com/phpde-nesne-yonelimli-programlama-5.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.webgelistirici.com/phpde-nesne-yonelimli-programlama-5.html</feedburner:origLink></item>
		<item>
		<title>Kohana 3.0 Notları: Basit Bir Örnek</title>
		<link>http://feedproxy.google.com/~r/webgelistirici/~3/HddvQdzNQfI/kohana-3-0-notlari-basit-bir-ornek.html</link>
		<comments>http://www.webgelistirici.com/kohana-3-0-notlari-basit-bir-ornek.html#comments</comments>
		<pubDate>Tue, 03 May 2011 15:02:42 +0000</pubDate>
		<dc:creator>Bülent Yılmaz</dc:creator>
				<category><![CDATA[Kohana]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[controller]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[model]]></category>
		<category><![CDATA[view]]></category>

		<guid isPermaLink="false">http://www.webgelistirici.com/?p=373</guid>
		<description><![CDATA[Makale içeriğini görmek için lütfen makale başlığına tıklayınız.]]></description>
			<content:encoded><![CDATA[<h2>Tablo yapısı</h2>
<p><code>"kisi"</code> adlı tablonun içeriği aşağıdaki gibi olsun.<br />
<a href="http://www.webgelistirici.com/wp-content/uploads/tablo.png"><img src="http://www.webgelistirici.com/wp-content/uploads/tablo.png" alt="" title="Tablo" width="204" height="104" class="aligncenter size-full wp-image-376" /></a></p>
<h2>Controller dosyası</h2>
<p><strong>Konum:</strong> <code>".../application/classes/controller/deneme.php"</code></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #990000;">defined</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'SYSPATH'</span><span style="color: #009900;">&#41;</span> or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'No direct script access.'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> Controller_Deneme <span style="color: #000000; font-weight: bold;">extends</span> Controller
<span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$model</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Bu nesne özelliği, model nesnemizi tutacak</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$view</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Bu nesne özelliği, view nesnemizi tutacak</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> before<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #666666; font-style: italic;">// Model nesnemizi tanımlayalım</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">model</span> <span style="color: #339933;">=</span> Model<span style="color: #339933;">::</span><span style="color: #004000;">factory</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'model1'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">// View nesnemizi tanımlayalım</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">view</span> <span style="color: #339933;">=</span> View<span style="color: #339933;">::</span><span style="color: #004000;">factory</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'view1'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> action_index<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #666666; font-style: italic;">// View içine model nesnemizin kisi_ad() yönteminin döndürdüğü değeri gönderelim</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">view</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">set</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'ad'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">model</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">kisi_ad</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'id'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">// View nesnemizin HTML çıktısını ekrana basalım</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">request</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">response</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">view</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">render</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p><span id="more-373"></span></p>
<h2>Model dosyası</h2>
<p><strong>Konum:</strong> <code>".../application/classes/model/model1.php"</code></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #990000;">defined</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'SYSPATH'</span><span style="color: #009900;">&#41;</span> or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'No direct script access.'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> Model_Model1 <span style="color: #000000; font-weight: bold;">extends</span> Model
<span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     * ID'si verilen kişinin adını döndürür.
     * 
     * @param     integer      Kişi ID'si
     * @return    string       Kişi adı
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> kisi_ad<span style="color: #009900;">&#40;</span><span style="color: #000088;">$id</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$sonuc</span> <span style="color: #339933;">=</span> DB<span style="color: #339933;">::</span><span style="color: #004000;">query</span><span style="color: #009900;">&#40;</span>Database<span style="color: #339933;">::</span><span style="color: #004000;">SELECT</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot; SELECT ad FROM kisi WHERE id = :id &quot;</span><span style="color: #009900;">&#41;</span>
                    <span style="color: #339933;">-&gt;</span><span style="color: #004000;">param</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">':id'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$id</span><span style="color: #009900;">&#41;</span>
                    <span style="color: #339933;">-&gt;</span><span style="color: #004000;">execute</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
                    <span style="color: #339933;">-&gt;</span><span style="color: #004000;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'ad'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// İlgili kaydın &quot;ad&quot; kolonundaki değer</span>
&nbsp;
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$sonuc</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Sonucu controller'a geri döndürelim</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

<h2>View dosyası</h2>
<p><strong>Konum:</strong> <code>".../application/views/view1.php"</code></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #990000;">defined</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'SYSPATH'</span><span style="color: #009900;">&#41;</span> or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'No direct script access.'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'Ad: '</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$ad</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Controller'dan gelen değeri ekrana basalım</span></pre></div></div>

<h2>Sonuç</h2>
<p><code>http://localhost/kohana/deneme?id=2</code> adresine istekte bulunuyoruz ve aşağıdaki sonucu alıyoruz.</p>
<p><a href="http://www.webgelistirici.com/wp-content/uploads/sonuc1.png"><img src="http://www.webgelistirici.com/wp-content/uploads/sonuc1.png" alt="" title="Sonuç" width="108" height="29" class="aligncenter size-full wp-image-378" /></a></p>
<img src="http://feeds.feedburner.com/~r/webgelistirici/~4/HddvQdzNQfI" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.webgelistirici.com/kohana-3-0-notlari-basit-bir-ornek.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.webgelistirici.com/kohana-3-0-notlari-basit-bir-ornek.html</feedburner:origLink></item>
		<item>
		<title>PHP’de Nesne Yönelimli Programlama-4</title>
		<link>http://feedproxy.google.com/~r/webgelistirici/~3/e-AHBY64lPo/phpde-nesne-yonelimli-programlama-4.html</link>
		<comments>http://www.webgelistirici.com/phpde-nesne-yonelimli-programlama-4.html#comments</comments>
		<pubDate>Mon, 02 May 2011 11:10:56 +0000</pubDate>
		<dc:creator>Bülent Yılmaz</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[class]]></category>
		<category><![CDATA[magic]]></category>
		<category><![CDATA[object]]></category>
		<category><![CDATA[__call]]></category>
		<category><![CDATA[__clone]]></category>
		<category><![CDATA[__construct]]></category>
		<category><![CDATA[__destruct]]></category>
		<category><![CDATA[__get]]></category>
		<category><![CDATA[__isset]]></category>
		<category><![CDATA[__set]]></category>
		<category><![CDATA[__sleep]]></category>
		<category><![CDATA[__toString]]></category>
		<category><![CDATA[__unset]]></category>
		<category><![CDATA[__wakeup]]></category>

		<guid isPermaLink="false">http://www.webgelistirici.com/?p=356</guid>
		<description><![CDATA[Makale içeriğini görmek için lütfen makale başlığına tıklayınız.]]></description>
			<content:encoded><![CDATA[<h2>Sihirli Yöntemler (Magic Methods)</h2>
<h2><code><strong>__construct()</strong></code></h2>
<p>Kurucu yöntemdir. Nesne oluşturulurken otomatik olarak çalıştırılır. Bu yöntem içine, nesnenin oluşturulma anında yapılması istenen ilklendirme işlemleri yazılabilir.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> sinif
<span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000088;">$isim</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __construct<span style="color: #009900;">&#40;</span><span style="color: #000088;">$ad</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">isim</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$ad</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000088;">$nesne</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> sinif<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Bülent'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
<span style="color: #666666; font-style: italic;">// Bu işlemden sonra $nesne-&gt;isim özelliğinin değeri &quot;Bülent&quot; olur</span></pre></div></div>

<p>Bir çocuk sınıftan nesne oluşturulurken, ata sınıfın kurucu yöntemi işletilmez. İşletilmek istenirse çocuk sınıfın kurucu yöntemi içinde <code>parent::__construct();</code> yazmak gerekir.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> sinif2 <span style="color: #000000; font-weight: bold;">extends</span> sinif1
<span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __construct<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        parent<span style="color: #339933;">::</span>__construct<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Önce sinif1 sınıfının kurucu yöntemini işlet</span>
        <span style="color: #339933;">...</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p><span id="more-356"></span></p>
<h2><code><strong>__destruct()</strong></code></h2>
<p>Yıkıcı yöntemdir. Betik sonlanırken veya nesne <code>unset()</code> ile yokedilirken devreye girer. Hafızayı boşaltmak, veritabanı bağlantısını koparmak vs. gibi sonlandırma işlemleri buraya yazılabilir.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> sinif
<span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$isim</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __destruct<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">isim</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">NULL</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Bir çocuk sınıftan nesne oluşturulurken, ata sınıfın yıkıcı yöntemi işletilmez. İşletilmek istenirse çocuk sınıfın yıkıcı yöntemi içinde <code>parent::__destruct();</code> yazmak gerekir.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> sinif2 <span style="color: #000000; font-weight: bold;">extends</span> sinif1
<span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __destruct<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        parent<span style="color: #339933;">::</span>__destruct<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Önce sinif1 sınıfının yıkıcı yöntemini işlet</span>
        <span style="color: #339933;">...</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<h2><code><strong>__call()</strong></code></h2>
<p>Sınıfın olmayan bir yöntemi çağrıldığında devreye girer.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __call<span style="color: #009900;">&#40;</span><span style="color: #000088;">$ad</span><span style="color: #339933;">,</span> <span style="color: #000088;">$parametreler_dizi</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// $ad : tanımsız yöntem adı</span>
    <span style="color: #666666; font-style: italic;">// $parametreler_dizi : yöntem çağrılırken kullanılan parametrelerden oluşan dizi</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">{$ad}</span> isminde yöntem yok!&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// $nesne-&gt;yontem() biçiminde olmayan bir yöntem çağrılırsa devreye girer</span></pre></div></div>

<h2><code><strong>__callStatic()</strong></code></h2>
<p>Sınıfın olmayan <code>static</code> bir yöntemi çağrıldığında devreye girer.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __callStatic<span style="color: #009900;">&#40;</span><span style="color: #000088;">$ad</span><span style="color: #339933;">,</span> <span style="color: #000088;">$parametreler_dizi</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// $ad : tanımsız yöntem adı</span>
    <span style="color: #666666; font-style: italic;">// $parametreler_dizi : yöntem çağrılırken kullanılan parametrelerden oluşan dizi</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">{$ad}</span> isminde yöntem yok!&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// sinif::yontem() biçiminde olmayan bir static yöntem çağrılırsa devreye girer</span></pre></div></div>

<h2><code><strong>__get()</strong></code></h2>
<p>Sınıfın olmayan bir özelliği çağrıldığında devreye girer.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __get<span style="color: #009900;">&#40;</span><span style="color: #000088;">$ad</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// $ad : tanımsız özellik adı</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">{$ad}</span> isminde özellik yok!&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<h2><code><strong>__set()</strong></code></h2>
<p>Sınıfın olmayan bir özelliğine değer atanmaya çalışıldığında devreye girer.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __set<span style="color: #009900;">&#40;</span><span style="color: #000088;">$ad</span><span style="color: #339933;">,</span> <span style="color: #000088;">$deger</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// $ad : tanımsız özellik adı</span>
    <span style="color: #666666; font-style: italic;">// $deger : atanmaya çalışılan değer</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">{$ad}</span> isminde özellik yok!&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<h2><code><strong>__isset()</strong></code></h2>
<p>Sınıfın olmayan bir özelliğinin <code>isset()</code> veya <code>empty()</code> fonksiyonu ile sınanması durumunda devreye girer.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __isset<span style="color: #009900;">&#40;</span><span style="color: #000088;">$ad</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// $ad : tanımsız özellik adı</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">{$ad}</span> isminde özellik yok!&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<h2><code><strong>__unset()</strong></code></h2>
<p>Sınıfın olmayan bir özelliğinin <code>unset()</code> fonksiyonu ile yokedilmeye çalışılması durumunda devreye girer.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __unset<span style="color: #009900;">&#40;</span><span style="color: #000088;">$ad</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// $ad : tanımsız özellik adı</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">{$ad}</span> isminde özellik yok!&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<h2><code><strong>__toString()</strong></code></h2>
<p>Nesnenin <code>echo</code> ile yazdırılmaya çalışılması durumunda devreye girer.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __toString<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// Nesnenin içeriğini formatlı olarak ekranda gösterelim</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;pre&gt;'</span> <span style="color: #339933;">.</span> <span style="color: #990000;">print_r</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#41;</span> <span style="color: #000088;">$this</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">TRUE</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&lt;/pre&gt;'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$nesne</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// şeklinde yazdırılmaya çalışılırsa devreye girecektir</span></pre></div></div>

<h2><code><strong>__clone()</strong></code></h2>
<p>Nesnenin <code>clon</code> operatörü ile çoğaltılması durumunda devreye girer.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> sinif
<span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000088;">$x</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000088;">$y</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __clone<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">x</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Başka nesneye o anki değeri ile değil de, 0 değeri ile aktarılsın</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000088;">$nesne1</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> sinif<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// $nesne1-&gt;x : 1 , $nesne1-&gt;y : 2</span>
<span style="color: #000088;">$nesne2</span> <span style="color: #339933;">=</span> clone <span style="color: #000088;">$nesne1</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// $nesne2-&gt;x : 0 , $nesne2-&gt;y : 2</span></pre></div></div>

<h2><code><strong>__sleep()</strong></code></h2>
<p>Nesne <code>serialize</code> işlemine tabi tutulursa devreye girer. Bu yöntemin, nesnenin sadece <code>serialize</code> işlemine katılması istenen özelliklerini içeren bir dizi döndürmesi beklenir.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> sinif
<span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000088;">$x</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000088;">$y</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000088;">$z</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">3</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __sleep<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'x'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'y'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
        <span style="color: #666666; font-style: italic;">// Bu durumda sadece &quot;x&quot; ve &quot;y&quot; özellikleri serialize işlemine katılır</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<h2><code><strong>__wakeup()</strong></code></h2>
<p>Nesne <code>unserialize</code> işlemine tabi tutulursa devreye girer.</p>
<img src="http://feeds.feedburner.com/~r/webgelistirici/~4/e-AHBY64lPo" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.webgelistirici.com/phpde-nesne-yonelimli-programlama-4.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.webgelistirici.com/phpde-nesne-yonelimli-programlama-4.html</feedburner:origLink></item>
		<item>
		<title>PHP’de Nesne Yönelimli Programlama-3</title>
		<link>http://feedproxy.google.com/~r/webgelistirici/~3/xjQC4kZ_PvM/phpde-nesne-yonelimli-programlama-3.html</link>
		<comments>http://www.webgelistirici.com/phpde-nesne-yonelimli-programlama-3.html#comments</comments>
		<pubDate>Fri, 22 Apr 2011 11:48:24 +0000</pubDate>
		<dc:creator>Bülent Yılmaz</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[class]]></category>
		<category><![CDATA[class_alias]]></category>
		<category><![CDATA[class_exists]]></category>
		<category><![CDATA[get_class]]></category>
		<category><![CDATA[get_class_methods]]></category>
		<category><![CDATA[get_class_vars]]></category>
		<category><![CDATA[get_object_vars]]></category>
		<category><![CDATA[get_parent_class]]></category>
		<category><![CDATA[instanceof]]></category>
		<category><![CDATA[is_subclass_of]]></category>
		<category><![CDATA[method_exists]]></category>
		<category><![CDATA[object]]></category>
		<category><![CDATA[property_exists]]></category>

		<guid isPermaLink="false">http://www.webgelistirici.com/?p=334</guid>
		<description><![CDATA[Makale içeriğini görmek için lütfen makale başlığına tıklayınız.]]></description>
			<content:encoded><![CDATA[<h2>Sınıf ve nesne işleçleri</h2>
<h2><code><strong>instanceof</strong></code></h2>
<p>Bir nesnenin bir sınıfın örneği olup olmadığını bulur. Bir nesnenin kalıtımla bağlı olduğu tüm ata sınıfları için <code>TRUE</code> sonuç döndürür.<br />
<strong style="text-decoration:underline;  font-size:11px;">Kullanımı:</strong><br />
<code>TRUE/FALSE &lt;= $nesne instanceof sinif</code></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> sinif
<span style="color: #009900;">&#123;</span>
    <span style="color: #339933;">...</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000088;">$a</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> sinif<span style="color: #339933;">;</span>
<span style="color: #990000;">var_dump</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$a</span> instanceof stdClass<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Çıktı: bool(false)</span>
&nbsp;
<span style="color: #000088;">$b</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>object<span style="color: #009900;">&#41;</span> <span style="color: #009900; font-weight: bold;">NULL</span><span style="color: #339933;">;</span>
<span style="color: #990000;">var_dump</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$b</span> instanceof stdClass<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Çıktı: bool(true)</span></pre></div></div>

<p><span id="more-334"></span></p>
<h2>Sınıf ve nesne fonksiyonları</h2>
<h2><code><strong>property_exists()</strong></code></h2>
<p>Sınıf veya nesnenin, belirtilen özelliğe sahip olup olmadığını saptar.<br />
<strong style="text-decoration:underline;  font-size:11px;">Kullanımı:</strong><br />
<code>TRUE/FALSE &lt;= property_exists('sinif', 'ozellik')<br />
TRUE/FALSE &lt;= property_exists($nesne, 'ozellik')</code></p>
<p><code>isset()</code> işlevinden farklı olarak, özellik değeri <code>NULL</code> olsa bile <code>TRUE</code> sonuç döndürür.</p>
<h2><code><strong>method_exists()</strong></code></h2>
<p>Sınıf veya nesnenin, belirtilen yönteme sahip olup olmadığını saptar.<br />
<strong style="text-decoration:underline;  font-size:11px;">Kullanımı:</strong><br />
<code>TRUE/FALSE &lt;= method_exists('sinif', 'yontem')<br />
TRUE/FALSE &lt;= method_exists($nesne, 'yontem')</code></p>
<h2><code><strong>class_exists()</strong></code></h2>
<p>Sınıfın tanımlı olup olmadığını saptar.<br />
<strong style="text-decoration:underline;  font-size:11px;">Kullanımı:</strong><br />
<code>TRUE/FALSE &lt;= class_exists('sinif'[, FALSE])</code></p>
<p>İkinci parametre <code>FALSE</code> verilirse, <code>__auto_load()</code> devre dışı bırakılıp sınama yapılır.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">class_exists</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'sinif'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$nesne</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> sinif<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<h2><code><strong>get_class()</strong></code></h2>
<p>Nesnenin türetildiği sınıfın adını döndürür, parametre nesne değilse <code>FALSE</code> döndürür.<br />
<strong style="text-decoration:underline;  font-size:11px;">Kullanımı:</strong><br />
<code>sinif_adi/FALSE &lt;= get_class($nesne)</code></p>
<h2><code><strong>get_parent_class()</strong></code></h2>
<p>Nesne veya sınıfın ebeveyn sınıfının ismini döndürür.<br />
<strong style="text-decoration:underline;  font-size:11px;">Kullanımı:</strong><br />
<code>sinif_adi/FALSE &lt;= get_parent_class($nesne)<br />
sinif_adi/FALSE &lt;= get_parent_class('sinif')</code></p>
<h2><code><strong>get_class_vars()</strong></code></h2>
<p>Sınıfın <code>public</code> olarak tanımlı özelliklerini dizi olarak döndürür.<br />
<strong style="text-decoration:underline;  font-size:11px;">Kullanımı:</strong><br />
<code>dizi &lt;= get_class_vars('sinif')</code></p>
<h2><code><strong>get_class_methods()</strong></code></h2>
<p>Sınıfın yöntemlerini dizi olarak döndürür.<br />
<strong style="text-decoration:underline;  font-size:11px;">Kullanımı:</strong><br />
<code>dizi &lt;= get_class_methods('sinif')</code></p>
<h2><code><strong>get_object_vars()</strong></code></h2>
<p>Nesnenin <code>static</code> olmayan tüm özelliklerini dizi olarak döndürür.<br />
<strong style="text-decoration:underline;  font-size:11px;">Kullanımı:</strong><br />
<code>dizi &lt;= get_object_vars($nesne)</code></p>
<h2><code><strong>class_alias()</strong></code></h2>
<p>Sınıfa takma ad tanımlamaya yarar.<br />
<strong style="text-decoration:underline;  font-size:11px;">Kullanımı:</strong><br />
<code>class_alias('sinif_eski_ad', 'sinif_yeni_ad');</code></p>
<h2><code><strong>is_subclass_of()</strong></code></h2>
<p>Bir sınıfın, başka bir sınıfın çocuk sınıfı olup olmadığını saptar.<br />
<strong style="text-decoration:underline;  font-size:11px;">Kullanımı:</strong><br />
<code>TRUE/FALSE &lt;= is_subclass_of('cocuk_sinif', 'ata_sinif')</code></p>
<img src="http://feeds.feedburner.com/~r/webgelistirici/~4/xjQC4kZ_PvM" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.webgelistirici.com/phpde-nesne-yonelimli-programlama-3.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.webgelistirici.com/phpde-nesne-yonelimli-programlama-3.html</feedburner:origLink></item>
		<item>
		<title>PHP’de Nesne Yönelimli Programlama-2</title>
		<link>http://feedproxy.google.com/~r/webgelistirici/~3/BwqvWghtMmU/phpde-nesne-yonelimli-programlama-2.html</link>
		<comments>http://www.webgelistirici.com/phpde-nesne-yonelimli-programlama-2.html#comments</comments>
		<pubDate>Thu, 21 Apr 2011 15:41:22 +0000</pubDate>
		<dc:creator>Bülent Yılmaz</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[autoload]]></category>
		<category><![CDATA[catch]]></category>
		<category><![CDATA[class]]></category>
		<category><![CDATA[object]]></category>
		<category><![CDATA[static]]></category>
		<category><![CDATA[stdclass]]></category>
		<category><![CDATA[try]]></category>
		<category><![CDATA[__class__]]></category>

		<guid isPermaLink="false">http://www.webgelistirici.com/?p=291</guid>
		<description><![CDATA[Makale içeriğini görmek için lütfen makale başlığına tıklayınız.]]></description>
			<content:encoded><![CDATA[<h2>&#8220;<code><strong>Static</strong></code>&#8221; tanımlı nesne üyeleri</h2>
<p><code>new</code> işleci ile nesne oluşturmaya gerek kalmadan, &#8220;<code>::</code>&#8221; işleci ile doğrudan sınıfın <code>static</code> tanımlı üyelerine erişilebilir. Nesne oluşturmadan <code>static</code> yöntem doğrudan çağrıldığında yeni bir nesne oluşturulmadığı için, sınıfın kurucu (<code>construct</code>) ve yıkıcı (<code>destruct</code>) metodları işletilmez.</p>
<p><span id="more-291"></span></p>
<p><strong><code><strong>Static</strong></code> tanımlı nesne üyelerinin kullanım şekilleri:</strong><br />
<code>sinif::$ozellik (her yerden)<br />
self::$ozellik (sınıf içinden)<br />
parent::$ozellik (türetilmiş sınıf içinden)</code></p>
<p><code>sinif::yontem() (her yerden)<br />
self::yontem() (sınıf içinden)<br />
parent::yontem() (türetilmiş sınıf içinden)</code></p>
<p><code>static</code> tanımlı yöntemler içinde iken <code>$this</code> sözde değişkeni kullanılamaz (nesne oluşmadığı için). <code>static</code> tanımlı özelliklere ve yöntemlere, &#8220;<code>-&gt;</code>&#8221; işleci ile erişilmeye çalışılırsa mantıksal hata (<code>warning</code>) oluşur.</p>
<p><strong><code><strong>Static</strong></code> tanımlı nesne üyelerini tanımlama şekilleri:</strong><br />
<code>[public/private/protected] static $ozellik;<br />
[public/private/protected] static function yontem() { ... }</code></p>
<p>Aşağıda <code>static</code> tanımlı özellik ve yöntem kullanımı ile ilgili bir örnek görülmektedir:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> sinif <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> static <span style="color: #000088;">$ozellik</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">5</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> static <span style="color: #000000; font-weight: bold;">function</span> yontem<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #000088;">$ozellik</span><span style="color: #339933;">++;</span> <span style="color: #666666; font-style: italic;">// static özelliklere &quot;$this-&gt;&quot; yerine &quot;self::&quot; ile erişilir</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Nesne oluşturmadan sınıfın static özellik ve yöntemlerini doğrudan kullanabiliriz</span>
sinif<span style="color: #339933;">::</span><span style="color: #004000;">yontem</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> sinif<span style="color: #339933;">::</span><span style="color: #000088;">$ozellik</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Çıktı : 6</span></pre></div></div>

<p><code>Static</code> tanımlı yöntemleri nesne oluşturarak da kullanabiliriz ancak <code>static</code> tanımlı özellikler de bu kullanım mümkün değildir.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$nesne</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> sinif<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Nesne oluşturarak da sınıfın static yöntemlerini kullanabiliriz</span>
<span style="color: #000088;">$nesne</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">yontem</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Static özellikler bu şekilde kullanılamaz</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$nesne</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ozellik</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// HATA</span></pre></div></div>

<p>Son olarak da <code>static</code> tanımlı bir özellik bellekte tutulduğu için yeni bir nesne tanımlandığında <code>static</code> tanımlı özelliğin bellekte tutulan son değeri ile nesne oluşturulur. <code>static</code> tanımlı değişken, belleğe bir kere yüklenir ve her defasında aynı bellek alanından çağrılır. İlk kullanıldığında belleğe atanır ve bir dahaki seferler oradan kullanılır. Her defasında nesne örneği oluşmayacağı için bellek tasarrufu sağlanır. <code>new</code> işleci ile nesne daha sonra oluşturulsa bile, ilgili <code>static</code> değişkenin bellekteki son değeri geçerli olur.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">sinif<span style="color: #339933;">::</span><span style="color: #004000;">yontem</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// 5 değeri 1 arttırılır</span>
&nbsp;
<span style="color: #b1b100;">echo</span> sinif<span style="color: #339933;">::</span><span style="color: #000088;">$ozellik</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Çıktı : 6</span>
&nbsp;
<span style="color: #000088;">$nesne</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> sinif<span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Nesne oluştur</span>
&nbsp;
<span style="color: #b1b100;">echo</span> sinif<span style="color: #339933;">::</span><span style="color: #000088;">$ozellik</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Çıktı : 6 (5 değil)</span></pre></div></div>

<p>Sonuç olarak, hep aynı değeri tutan özelliklerin ve hep aynı sonucu döndüren yöntemlerin <code>static</code> olarak tanımlanması daha iyidir.</p>
<h2>Otomatik sınıf yükleme (Autoload)</h2>
<p>Sayfada herhangi bir sınıf çağrıldığında, o sınıfın tanımlı olduğu dosyayı bizim yerimize otomatik olarak sayfaya dahil (<code>include</code>) etmeye yarar. Bunun için ön koşul, sınıf tanımlarının bulunduğu dosyaların hep aynı dizin içinde bulunmasıdır. </p>
<p>Örneğin &#8220;<code><strong>kutu</strong></code>&#8221; isimli sınıf, &#8220;<code>../sinif/<strong>kutu</strong>.sinif.php</code>&#8221; dosyası içinde tanımlı ise;</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// Bu fonksiyon sayfa içinde herhangi bir yerde tanımlanır</span>
<span style="color: #000000; font-weight: bold;">function</span> __autoload<span style="color: #009900;">&#40;</span><span style="color: #000088;">$sinif_adi</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">require_once</span> <span style="color: #0000ff;">&quot;../sinif/<span style="color: #006699; font-weight: bold;">{$sinif_adi}</span>.sinif.php&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Nesneyi tanımlayalım</span>
<span style="color: #000088;">$nesne</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> kutu<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Sınıf çağrıldığı anda, sınıfın tanımlı olduğu dosya otomatik dahil edilir</span></pre></div></div>

<p>Böylece sadece sayfada kullanılan sınıfların dosyaları sayfaya dahil ediliyor. Kullanılmayan sınıf dosyaları dahil edilmiyor. Eğer sayfada hiç sınıf kullanılmamışsa hiçbir sınıf dosyası da gereksiz yere sayfaya dahil edilmemiş oluyor.</p>
<h2><code><strong>__CLASS__</strong></code> sihirli sabiti</h2>
<p>İçinde bulunulan sınıfın adını verir.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// Sınıf içinde herhangi bir yerde iken;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #009900; font-weight: bold;">__CLASS__</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Çıktı: sinif_adi</span></pre></div></div>

<h2><code><strong>__METHOD__</strong></code> sihirli sabiti</h2>
<p>İçinde bulunulan yöntemin ve o yöntemin ait olduğu sınıfın adını birlikte verir.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// Sınıfın herhangi bir yöntemi içinde iken;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #009900; font-weight: bold;">__METHOD__</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Çıktı: sinif_adi::yontem_adi</span></pre></div></div>

<h2>Öntanımlı <code><strong>stdClass</strong></code> sınıfı</h2>
<p>PHP&#8217;de öntanımlı olarak bulunan boş bir sınıf şablonudur.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">var_dump</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> stdClass<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// stdClass Object () , boş sınıf</span>
<span style="color: #990000;">var_dump</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>object<span style="color: #009900;">&#41;</span> <span style="color: #009900; font-weight: bold;">NULL</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// stdClass Object () , boş sınıf</span>
<span style="color: #990000;">var_dump</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>object<span style="color: #009900;">&#41;</span> <span style="color: #0000ff;">'a'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// stdClass Object ( [scalar] =&gt; a )</span>
<span style="color: #990000;">var_dump</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>object<span style="color: #009900;">&#41;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'a'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'b'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// stdClass Object ( [a] =&gt; 1 [b] =&gt; 2 )</span></pre></div></div>

<h2>Diziyi nesneye dönüştürme</h2>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// Aşağıdaki gibi çok boyutlu bir dizimiz olsun</span>
&nbsp;
<span style="color: #000088;">$dizi</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
	<span style="color: #0000ff;">'a'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Bülent'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'b'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span> 	<span style="color: #666666; font-style: italic;">/* Elemanları dizi olan dizi */</span>
		        <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
		            <span style="color: #0000ff;">'x'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">5</span><span style="color: #339933;">,</span>
		            <span style="color: #0000ff;">'y'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">10</span>
		        <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
		        <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
		            <span style="color: #0000ff;">'q'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">15</span><span style="color: #339933;">,</span>
		            <span style="color: #0000ff;">'w'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">20</span>
		        <span style="color: #009900;">&#41;</span>
                <span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$dizi</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'a'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Çıktı: &quot;Bülent&quot;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$dizi</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'b'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'y'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Çıktı: 10</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$dizi</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'b'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'q'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Çıktı: 15</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Dizileri nesnelere dönüştürerek kullanalım</span>
&nbsp;
<span style="color: #000088;">$nesne</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>object<span style="color: #009900;">&#41;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
	<span style="color: #0000ff;">'a'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Bülent'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'b'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span> 	<span style="color: #666666; font-style: italic;">/* Elemanları nesne olan dizi */</span>
		        <span style="color: #009900;">&#40;</span>object<span style="color: #009900;">&#41;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
		            <span style="color: #0000ff;">'x'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">5</span><span style="color: #339933;">,</span>
		            <span style="color: #0000ff;">'y'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">10</span>
		        <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
	        	<span style="color: #009900;">&#40;</span>object<span style="color: #009900;">&#41;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
	        	    <span style="color: #0000ff;">'q'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">15</span><span style="color: #339933;">,</span>
	        	    <span style="color: #0000ff;">'w'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">20</span>
		        <span style="color: #009900;">&#41;</span>
    	        <span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$nesne</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">a</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Çıktı: &quot;Bülent&quot;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$nesne</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">b</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">y</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Çıktı: 10</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$nesne</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">b</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">q</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Çıktı: 15</span></pre></div></div>

<h2>Nesneyi diziye dönüştürme</h2>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> sinif
<span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000088;">$var1</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000088;">$var2</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$var3</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">3</span><span style="color: #339933;">;</span>
    static <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000088;">$var4</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">4</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">const</span> SABIT <span style="color: #339933;">=</span> <span style="color: #cc66cc;">5</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> yontem<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'merhaba'</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000088;">$nesne</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> sinif<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;pre&gt;'</span> <span style="color: #339933;">.</span> <span style="color: #990000;">print_r</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#41;</span> <span style="color: #000088;">$nesne</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">TRUE</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&lt;/pre&gt;'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/*
Çıktı:
&nbsp;
Array
(
    [var1] =&gt; 1
    [ *var2] =&gt; 2
    [ sinifvar3] =&gt; 3
)
// Protected özellik başında &quot;*&quot; ile gösterilir
// Private özellik başında sınıf adı ile gösterilir
// Static özellik ve sabit, diziye aktarılmaz
// Sınıfın yöntemleri tip dönüşümü ile aktarılamaz
*/</span></pre></div></div>

<h2>Nesneyi döngüde kullanma</h2>
<p>Nesneleri tip dönüşümü yapmadan doğrudan <code>foreach</code> ile birlikte kullanabiliyoruz.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> sinif <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000088;">$x</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">5</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000088;">$y</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">6</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">public</span> static <span style="color: #000088;">$z</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">7</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000088;">$q</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">8</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$w</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">9</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> yontem<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'merhaba'</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000088;">$nesne</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> sinif<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$nesne</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$anahtar</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$deger</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;div&gt;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$anahtar</span><span style="color: #339933;">.</span><span style="color: #0000ff;">' = '</span><span style="color: #339933;">.</span><span style="color: #000088;">$deger</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;/div&gt;'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/*
Çıktı:
&nbsp;
x = 5
y = 6
// static özellik esgeçilir
// private ve protected özellikler esgeçilir
*/</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Burada ise nesneyi önce diziye aktarıp sonra döngüye sokuyoruz</span>
<span style="color: #666666; font-style: italic;">// Bu durumda static özellik dışındaki özellikler diziye aktarılacaktır</span>
<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#41;</span> <span style="color: #000088;">$nesne</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$anahtar</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$deger</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;div&gt;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$anahtar</span><span style="color: #339933;">.</span><span style="color: #0000ff;">' = '</span><span style="color: #339933;">.</span><span style="color: #000088;">$deger</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;/div&gt;'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/*
Çıktı:
&nbsp;
x = 5
y = 6
x = 5
y = 6
*q = 8
sinifw = 9
*/</span></pre></div></div>

<h2>NYP uyumlu karar kontrol mekanizması (<code><strong>try-catch</strong></code>)</h2>
<p>PHP 5 ile gelen, nesne yönelimli programlama (NYP) uyumlu karar kontrol mekanizması;</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">try
<span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span> <span style="color: #990000;">is_int</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$x</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> Exception<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Sayı değil!'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #666666; font-style: italic;">// veya</span>
        <span style="color: #666666; font-style: italic;">// trigger_error('Sayı değil!', E_USER_ERROR);</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
catch <span style="color: #009900;">&#40;</span>Exception <span style="color: #000088;">$hata</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
        <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$hata</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getMessage</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Bir başka örnek;</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> hata<span style="color: #009900;">&#40;</span><span style="color: #000088;">$hata</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$mesaj</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'&lt;p&gt;Hatanın oluştuğu dosya adı = '</span>
               <span style="color: #339933;">.</span> <span style="color: #000088;">$hata</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getFile</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&lt;/p&gt;'</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$mesaj</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'&lt;p&gt;Hatanın oluştuğu satır no = '</span>
               <span style="color: #339933;">.</span> <span style="color: #000088;">$hata</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getLine</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&lt;/p&gt;'</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$mesaj</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'&lt;p&gt;Hata mesajı = '</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$hata</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getMessage</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&lt;/p&gt;'</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$mesaj</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'&lt;p&gt;Hata kodu = '</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$hata</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getCode</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&lt;/p&gt;'</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$mesaj</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
try
<span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> Exception<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Hata oluştu!'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
catch <span style="color: #009900;">&#40;</span>Exception <span style="color: #000088;">$hata</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
        <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span>hata<span style="color: #009900;">&#40;</span><span style="color: #000088;">$hata</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<img src="http://feeds.feedburner.com/~r/webgelistirici/~4/BwqvWghtMmU" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.webgelistirici.com/phpde-nesne-yonelimli-programlama-2.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.webgelistirici.com/phpde-nesne-yonelimli-programlama-2.html</feedburner:origLink></item>
		<item>
		<title>PHP’de Nesne Yönelimli Programlama-1</title>
		<link>http://feedproxy.google.com/~r/webgelistirici/~3/aF5DDzy0XcQ/phpde-nesne-yonelimli-programlama-1.html</link>
		<comments>http://www.webgelistirici.com/phpde-nesne-yonelimli-programlama-1.html#comments</comments>
		<pubDate>Wed, 20 Apr 2011 12:30:22 +0000</pubDate>
		<dc:creator>Bülent Yılmaz</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[chaining]]></category>
		<category><![CDATA[class]]></category>
		<category><![CDATA[constant]]></category>
		<category><![CDATA[extends]]></category>
		<category><![CDATA[final]]></category>
		<category><![CDATA[method]]></category>
		<category><![CDATA[object]]></category>
		<category><![CDATA[oop]]></category>
		<category><![CDATA[private]]></category>
		<category><![CDATA[protected]]></category>
		<category><![CDATA[public]]></category>
		<category><![CDATA[zincirleme]]></category>

		<guid isPermaLink="false">http://www.webgelistirici.com/?p=284</guid>
		<description><![CDATA[Makale içeriğini görmek için lütfen makale başlığına tıklayınız.]]></description>
			<content:encoded><![CDATA[<p>Nesne yönelimli programlama (object oriented programming-OOP) mantığı; programcının nesne içerisinde ne yazıldığını bilmeksizin sadece fonksiyonların yaptığı işi bilerek kullanmasıdır ve böylece programcılar arasındaki eşgüdümü sağlamayı kolaylaştırır. Bu yazılım geliştirme yaklaşımında, bir yöntemin nasıl çalıştığını değil, nasıl kullanıldığını bilmek yeterlidir.</p>
<h2>Sınıf örneği (nesne) oluşturma</h2>
<p>Bir sınıftan türetilen nesneye, o sınıfın <strong>örneği</strong> (<em>instance</em>) denir. Nesne oluşturma işine ise <strong>örnekleme</strong> denir. </p>
<p>Sınıf örneği oluşturmak (nesne oluşturmak) için &#8220;<code>new</code>&#8221; işlecinden faydalanılır. Bir nesne, sınıf adı ile veya sınıfın kurucu (constructor) yöntemi ile tanımlanabilir.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$nesne</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> sinif<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// kurucu yöntem ile tanımlamak</span>
<span style="color: #666666; font-style: italic;">// bu kullanımda sınıf tanımlanırken kurucu yönteme parametre de geçirilebilir</span>
<span style="color: #000088;">$nesne</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> sinif<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">5</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//veya</span>
&nbsp;
<span style="color: #000088;">$nesne</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> sinif<span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// sınıf adı ile tanımlamak</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Not: Türetilen nesnenin, sınıfla aynı isimde olmasında sakınca yoktur</span>
<span style="color: #000088;">$x</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> x<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p><span id="more-284"></span></p>
<h2>Sınıf tanımlama</h2>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> sinif
<span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$ad</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> ad_ata<span style="color: #009900;">&#40;</span><span style="color: #000088;">$x</span><span style="color: #009900;">&#41;</span> <span style="color: #666666; font-style: italic;">// Setter method</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ad</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$x</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> ad_getir<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #666666; font-style: italic;">// Getter method</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ad</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000088;">$nesne</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> sinif<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$nesne</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ad_ata</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Bülent'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$nesne</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ad_getir</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<h2>Sınıf üyeleri</h2>
<p>Bir sınıfın 2 tipte üyesi bulunabilir:</p>
<ul>
<li><strong>Özellik</strong> (<em>Property</em>) : Sınıfın değişken ve sabitleri</li>
<li><strong>Yöntem</strong> (<em>Method</em>) : Sınıfın fonksiyonları</li>
</ul>
<p>Aşağıda 4 adet üyesi bulunan bir sınıf görülmektedir:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> sinif <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// Sınıfın özellikleri</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000088;">$x</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">5</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Sınıfın özelliği</span>
    <span style="color: #000000; font-weight: bold;">const</span> SABIT <span style="color: #339933;">=</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Sınıfın özelliği</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// Sınıfın yöntemleri</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> fonk1<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #666666; font-style: italic;">// Sınıfın yöntemi</span>
    <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> fonk2<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #666666; font-style: italic;">// Sınıfın yöntemi</span>
    <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span>    
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

<h2>Sınıf üyelerinin erişim niteleyicileri (Access Modifiers)</h2>
<p>Sınıf üyelerine erişimi denetlemeye ve sınırlandırmaya yararlar. Bilgi güvenliği ve oluşabilecek hataların minimize edilmesi ana amaçtır.</p>
<ul>
<li><code><strong>Public</strong></code> (Varsayılan) : Her yerden erişilebilir (sınırlama yok). Niteleyici belirtilmemişse, varsayılan olarak <code>public</code> olarak kabul edilir. Kalıtımla türetilen sınıfa aktarılır.</li>
<li><code><strong>Protected</strong></code> : Sadece kendi sınıfının içinden ve türetilen bir sınıf içinden erişilebilir. Dışarıdan erişilemez. <code>Private</code>&#8216;den tek farkı; kalıtımla türetilen sınıfa aktarılır.</li>
<li><code><strong>Private</strong></code> : Sadece kendi sınıfının içinden erişilebilir. Türetilen sınıf içinden ve dışarıdan erişilemez. Kalıtımla türetilen sınıfa aktarılmaz.</li>
</ul>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> sinif <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$ozellik1</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">3</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Türetilen sınıfa değeri aktarılmaz</span>
    <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000088;">$ozellik2</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">5</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Türetilen sınıfa değeri aktarılır</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> sinif2 <span style="color: #000000; font-weight: bold;">extends</span> sinif <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> goster<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;ozellik1 = <span style="color: #006699; font-weight: bold;">{$this-&gt;ozellik1}</span>&lt;br/&gt;&quot;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;ozellik2 = <span style="color: #006699; font-weight: bold;">{$this-&gt;ozellik2}</span>&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000088;">$nesne</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> sinif2<span style="color: #339933;">;</span>
<span style="color: #000088;">$nesne</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">goster</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/*
Çıktı:
&nbsp;
ozellik1 =
ozellik2 = 5
*/</span></pre></div></div>

<p>Sınıfın bir yöntemi içinde tanımlanmamış bir değişkeni doğrudan kullanırsak, o değişken sadece o yöntem içinde geçerli olan yerel bir değişken olmuş. Sınıfın diğer yöntemleri tarafından kullanılamaz. Örneğin aşağıdaki gibi bir kullanım hataya neden olacaktır.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> sinif <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> yontem1<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$x</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">5</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Bu değişken sadece bu yöntem içinde kullanılabilir</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> yontem2<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$x</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// HATA</span>
    <span style="color: #009900;">&#125;</span>    
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Sınıf içinde bir özelliği tanımlamadan doğrudan kullanmamız durumunda, <code>public</code> olarak tanımlanmış gibi kabul edilecektir.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> sinif <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// Normalde burada tanımlamamız gerekir</span>
    <span style="color: #666666; font-style: italic;">// public $ozellik;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> yontem<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ozellik</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">5</span><span style="color: #339933;">;</span> 
        <span style="color: #666666; font-style: italic;">// Bu nesne özelliği public olarak tanımlanmış gibi kabul edilir</span>
&nbsp;
        <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ozellik</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000088;">$nesne</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> sinif<span style="color: #339933;">;</span>
<span style="color: #000088;">$nesne</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">yontem</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Çıktı: 5</span></pre></div></div>

<h2>Sınıf içinde sabit tanımlama</h2>
<p>Sınıf içinde tanımlanan sabitin, <code>static</code> ve <code>public</code> özellik gösterir. Yani &#8220;<code>::</code>&#8221; işleci ile her yerden (nesne tanımlanmamış olsa bile) çağrılabilir.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> sinif
<span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">const</span> SABIT <span style="color: #339933;">=</span> <span style="color: #cc66cc;">5</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> yontem<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">echo</span> <span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #004000;">SABIT</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #b1b100;">echo</span> sinif<span style="color: #339933;">::</span><span style="color: #004000;">SABIT</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Çıktı: 5</span>
&nbsp;
<span style="color: #000088;">$nesne</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> sinif<span style="color: #339933;">;</span>
<span style="color: #000088;">$nesne</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">yontem</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Çıktı: 5</span></pre></div></div>

<p><strong>Kullanım şekilleri;</strong><br />
<code>sinif::SABIT // Herhangi bir yerden çağırırken<br />
self::SABIT // Sınıf içinde çağırırken<br />
parent::SABIT // Türetilmiş sınıf içinden çağırırken</code></p>
<h2>Kalıtım</h2>
<p>PHP’de sadece tekli kalıtım desteklenir yani bir sınıf aynı anda sadece tek bir sınıftan kalıtılabilir. Kendisinden türetme yapılan sınıfa <strong>ata sınıf</strong> veya <strong>ebeveyn sınıf</strong> (<em>parent class</em>), türetilen yeni sınıfa ise <strong>çocuk sınıf</strong> (<em>child class</em>) denir.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> cocuk_sinif <span style="color: #000000; font-weight: bold;">extends</span> ata_sinif
<span style="color: #009900;">&#123;</span>
    <span style="color: #339933;">...</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>&#8220;<code>final</code>&#8221; anahtar kelimesi ile bir sınıf kısırlaştırılabilir. Bu durumda o sınıftan başka bir sınıf türetilemez. Türetilmeye çalışılırsa ölümcül hata (<code>fatal error</code>) oluşur.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">final <span style="color: #000000; font-weight: bold;">class</span> cocuk_sinif <span style="color: #000000; font-weight: bold;">extends</span> ata_sinif
<span style="color: #009900;">&#123;</span>
    <span style="color: #339933;">...</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Bu durumda &#8220;<code>cocuk_sinif</code>&#8221; adlı sınıftan yeni bir sınıf türetilemeyecektir.</p>
<p>PHP&#8217;de nesne yöntemlerinin üzerine yazılmasına (<code>override</code>) izin verilir. Yani türetilen sınıf içinde, ata sınıfın yöntemlerinden birisinin adı ile yeni bir yöntem tanımlanabilir ve bu durumda ata sınıf içindeki yöntemin üzerine yazılmış olur.</p>
<p>Üzerine yazılmasını engellemek istediğimiz yöntemleri &#8220;<code>final</code>&#8221; anahtar kelimesi ile tanımlarsak, o sınıftan türetilen diğer sınıflarda bu yöntem ile aynı isimde yeni bir yöntem tanımlanamaz. Aksi halde ölümcül hata (<code>fatal error</code>) oluşur.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> ata_sinif <span style="color: #009900;">&#123;</span>
&nbsp;
    final <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> yontem<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #339933;">...</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> cocuk_sinif <span style="color: #000000; font-weight: bold;">extends</span> ata_sinif <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> yontem<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #666666; font-style: italic;">// fatal error</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #339933;">...</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

<h2>Nesneyi çoğaltma</h2>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// (1) Doğrudan atama (referans atama ile eşdeğerdir)</span>
<span style="color: #666666; font-style: italic;">// Birbirlerinden eşzamanlı olarak etkilenirler</span>
<span style="color: #666666; font-style: italic;">// Tek fark birine NULL atanırsa diğeri etkilenmez</span>
<span style="color: #000088;">$nesne2</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$nesne1</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// (2) Referans atama</span>
<span style="color: #666666; font-style: italic;">// Birbirlerinden eşzamanlı olarak etkilenirler</span>
<span style="color: #666666; font-style: italic;">// Birine NULL atanırsa ikisi de NULL olur</span>
<span style="color: #000088;">$nesne_ref</span> <span style="color: #339933;">=</span> <span style="color: #339933;">&amp;</span> <span style="color: #000088;">$nesne1</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// (3) Kopyasını çıkarma</span>
<span style="color: #666666; font-style: italic;">// Birbirlerinden bağımsızdırlar ve etkilenmezler</span>
<span style="color: #000088;">$nesne3</span> <span style="color: #339933;">=</span> clone <span style="color: #000088;">$nesne1</span><span style="color: #339933;">;</span></pre></div></div>

<p><code>unset()</code>, her koşulda sadece işlem yapılan nesneyi siler.<br />
<code>NULL</code> atamak, işlem yapılan nesneyi ve o nesnenin referans ile ilişkili olduğu diğer nesneleri de <code>NULL</code> yapar.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">unset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$nesne1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Sadece $nesne1 nesnesi silinir</span>
&nbsp;
<span style="color: #000088;">$nesne1</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">NULL</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Bu durumda $nesne_ref nesnesi de NULL olur</span></pre></div></div>

<h2>Yöntem zincirleme</h2>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> sinif <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> yontem1<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		…
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">/* Zincirleme için gerekli */</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> yontem2<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		…
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">/* Zincirleme için gerekli */</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> yontem3<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		…
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">/* Zincirleme için gerekli */</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000088;">$nesne</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> sinif<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$nesne</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">yontem1</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
      <span style="color: #339933;">-&gt;</span><span style="color: #004000;">yontem2</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
      <span style="color: #339933;">-&gt;</span><span style="color: #004000;">yontem3</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Zincirleyerek 3 yöntemi arka arkaya çalıştırıyoruz</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// veya</span>
&nbsp;
<span style="color: #000088;">$nesne</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">yontem1</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Ayrı ayrı çalıştırıyoruz</span>
<span style="color: #000088;">$nesne</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">yontem2</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$nesne</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">yontem3</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<img src="http://feeds.feedburner.com/~r/webgelistirici/~4/aF5DDzy0XcQ" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.webgelistirici.com/phpde-nesne-yonelimli-programlama-1.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.webgelistirici.com/phpde-nesne-yonelimli-programlama-1.html</feedburner:origLink></item>
		<item>
		<title>Kohana 3.0 Notları: Veritabanı Kullanımı</title>
		<link>http://feedproxy.google.com/~r/webgelistirici/~3/_jJ6JeUSe7c/kohana-3-0-notlari-veritabani-kullanimi.html</link>
		<comments>http://www.webgelistirici.com/kohana-3-0-notlari-veritabani-kullanimi.html#comments</comments>
		<pubDate>Tue, 19 Apr 2011 15:34:37 +0000</pubDate>
		<dc:creator>Bülent Yılmaz</dc:creator>
				<category><![CDATA[Kohana]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[bind]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[db]]></category>
		<category><![CDATA[param]]></category>
		<category><![CDATA[parameters]]></category>
		<category><![CDATA[prepare]]></category>
		<category><![CDATA[query builder]]></category>

		<guid isPermaLink="false">http://www.webgelistirici.com/?p=273</guid>
		<description><![CDATA[Makale içeriğini görmek için lütfen makale başlığına tıklayınız.]]></description>
			<content:encoded><![CDATA[<h2>Sorguyu doğrudan işletme</h2>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// current() ile SELECT işlemi</span>
<span style="color: #000088;">$dizi</span> <span style="color: #339933;">=</span> DB<span style="color: #339933;">::</span><span style="color: #004000;">query</span><span style="color: #009900;">&#40;</span>Database<span style="color: #339933;">::</span><span style="color: #004000;">SELECT</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot; SELECT * FROM personel WHERE personel_id = 243 &quot;</span><span style="color: #009900;">&#41;</span>
   <span style="color: #339933;">-&gt;</span><span style="color: #004000;">execute</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
   <span style="color: #339933;">-&gt;</span><span style="color: #004000;">current</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Tek bir kayıt (dizi olarak) döndürür</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// as_array() ile SELECT işlemi</span>
<span style="color: #000088;">$dizi</span> <span style="color: #339933;">=</span> DB<span style="color: #339933;">::</span><span style="color: #004000;">query</span><span style="color: #009900;">&#40;</span>Database<span style="color: #339933;">::</span><span style="color: #004000;">SELECT</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot; SELECT * FROM personel WHERE bolum_id = 12 &quot;</span><span style="color: #009900;">&#41;</span>
   <span style="color: #339933;">-&gt;</span><span style="color: #004000;">execute</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
   <span style="color: #339933;">-&gt;</span><span style="color: #004000;">as_array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Birden çok kayıt (dizi olarak) döndürür</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// get() ile SELECT işlemi</span>
<span style="color: #000088;">$deger</span> <span style="color: #339933;">=</span> DB<span style="color: #339933;">::</span><span style="color: #004000;">query</span><span style="color: #009900;">&#40;</span>Database<span style="color: #339933;">::</span><span style="color: #004000;">SELECT</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot; SELECT isim FROM personel WHERE personel_id = 243 &quot;</span><span style="color: #009900;">&#41;</span>
   <span style="color: #339933;">-&gt;</span><span style="color: #004000;">execute</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
   <span style="color: #339933;">-&gt;</span><span style="color: #004000;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'isim'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Tek bir değer  döndürür</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// INSERT işlemi</span>
DB<span style="color: #339933;">::</span><span style="color: #004000;">query</span><span style="color: #009900;">&#40;</span>Database<span style="color: #339933;">::</span><span style="color: #004000;">INSERT</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot; INSERT bolumler ('bolum_id', 'silindi') VALUES (12, 'H') &quot;</span><span style="color: #009900;">&#41;</span>
   <span style="color: #339933;">-&gt;</span><span style="color: #004000;">execute</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// UPDATE işlemi</span>
DB<span style="color: #339933;">::</span><span style="color: #004000;">query</span><span style="color: #009900;">&#40;</span>Database<span style="color: #339933;">::</span><span style="color: #004000;">UPDATE</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot; UPDATE bolumler SET silindi = 'H' WHERE bolum_id = 12 &quot;</span><span style="color: #009900;">&#41;</span>
   <span style="color: #339933;">-&gt;</span><span style="color: #004000;">execute</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// DELETE işlemi</span>
DB<span style="color: #339933;">::</span><span style="color: #004000;">query</span><span style="color: #009900;">&#40;</span>Database<span style="color: #339933;">::</span><span style="color: #004000;">DELETE</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot; DELETE bolumler WHERE bolum_id = 12 &quot;</span><span style="color: #009900;">&#41;</span>
   <span style="color: #339933;">-&gt;</span><span style="color: #004000;">execute</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p><span id="more-273"></span></p>
<h2>Sorguya parametre gönderme (Preparing)</h2>
<p>Sabit (literal) değerler <code>param()</code> yöntemi ile, değişkenler <code>bind()</code> yöntemi ile aktarılır. <code>parameters()</code> yöntemi ile, dizi şeklinde çoklu kullanım da mümkündür.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$dizi</span> <span style="color: #339933;">=</span> DB<span style="color: #339933;">::</span><span style="color: #004000;">query</span><span style="color: #009900;">&#40;</span>Database<span style="color: #339933;">::</span><span style="color: #004000;">SELECT</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot; SELECT * FROM personel WHERE bolum_id = :bolum_id AND silindi = :silindi &quot;</span><span style="color: #009900;">&#41;</span>
   <span style="color: #339933;">-&gt;</span><span style="color: #004000;">param</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">':bolum_id'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">12</span><span style="color: #009900;">&#41;</span>
   <span style="color: #339933;">-&gt;</span><span style="color: #004000;">param</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">':silindi'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'H'</span><span style="color: #009900;">&#41;</span>
   <span style="color: #339933;">-&gt;</span><span style="color: #004000;">execute</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
   <span style="color: #339933;">-&gt;</span><span style="color: #004000;">as_array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// veya</span>
&nbsp;
<span style="color: #000088;">$dizi</span> <span style="color: #339933;">=</span> DB<span style="color: #339933;">::</span><span style="color: #004000;">query</span><span style="color: #009900;">&#40;</span>Database<span style="color: #339933;">::</span><span style="color: #004000;">SELECT</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot; SELECT * FROM personel WHERE bolum_id = :bolum_id AND silindi = :silindi &quot;</span><span style="color: #009900;">&#41;</span>
   <span style="color: #339933;">-&gt;</span><span style="color: #004000;">parameters</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">':bolum_id'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">12</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">':silindi'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'H'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
   <span style="color: #339933;">-&gt;</span><span style="color: #004000;">execute</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
   <span style="color: #339933;">-&gt;</span><span style="color: #004000;">as_array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// veya</span>
&nbsp;
<span style="color: #000088;">$dizi</span> <span style="color: #339933;">=</span> DB<span style="color: #339933;">::</span><span style="color: #004000;">query</span><span style="color: #009900;">&#40;</span>Database<span style="color: #339933;">::</span><span style="color: #004000;">SELECT</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot; SELECT * FROM personel WHERE bolum_id = :bolum_id AND silindi = :silindi &quot;</span><span style="color: #009900;">&#41;</span>
   <span style="color: #339933;">-&gt;</span><span style="color: #004000;">bind</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">':bolum_id'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$bolum_id</span><span style="color: #009900;">&#41;</span>
   <span style="color: #339933;">-&gt;</span><span style="color: #004000;">bind</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">':silindi'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$silindi</span><span style="color: #009900;">&#41;</span>
   <span style="color: #339933;">-&gt;</span><span style="color: #004000;">execute</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
   <span style="color: #339933;">-&gt;</span><span style="color: #004000;">as_array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<h2>Zincirleyerek sorgu işletme (Query Builder)</h2>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// SELECT işlemi</span>
<span style="color: #000088;">$dizi</span> <span style="color: #339933;">=</span> DB<span style="color: #339933;">::</span><span style="color: #004000;">select</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'id'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'isim'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'ad'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'tel'</span><span style="color: #009900;">&#41;</span>
   <span style="color: #339933;">-&gt;</span><span style="color: #004000;">distinct</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">TRUE</span><span style="color: #009900;">&#41;</span>
   <span style="color: #339933;">-&gt;</span><span style="color: #004000;">from</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'personel'</span><span style="color: #009900;">&#41;</span>
   <span style="color: #339933;">-&gt;</span><span style="color: #004000;">where</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'bolum_id'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'='</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">12</span><span style="color: #009900;">&#41;</span>
   <span style="color: #339933;">-&gt;</span><span style="color: #004000;">or_where</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'bolum_id'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'='</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">15</span><span style="color: #009900;">&#41;</span>
   <span style="color: #339933;">-&gt;</span><span style="color: #004000;">order_by</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'tarih'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'DESC'</span><span style="color: #009900;">&#41;</span>
   <span style="color: #339933;">-&gt;</span><span style="color: #004000;">limit</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">10</span><span style="color: #009900;">&#41;</span>
   <span style="color: #339933;">-&gt;</span><span style="color: #004000;">execute</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
   <span style="color: #339933;">-&gt;</span><span style="color: #004000;">as_array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// Sorgu: &quot;SELECT DISTINCT id, isim AS ad, tel FROM personel WHERE bolum_id = 12 OR bolum_id = 15 ORDER BY tarih DESC LIMIT 10&quot;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// INSERT işlemi</span>
DB<span style="color: #339933;">::</span><span style="color: #004000;">insert</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'personel'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'isim'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'tel'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
   <span style="color: #339933;">-&gt;</span><span style="color: #004000;">values</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$isim</span><span style="color: #339933;">,</span> <span style="color: #000088;">$tel</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
   <span style="color: #339933;">-&gt;</span><span style="color: #004000;">execute</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// Sorgu: &quot;INSERT personel ('isim', 'tel') VALUES ($isim, $tel)&quot;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// UPDATE işlemi</span>
DB<span style="color: #339933;">::</span><span style="color: #004000;">update</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'personel'</span><span style="color: #009900;">&#41;</span>
   <span style="color: #339933;">-&gt;</span><span style="color: #004000;">set</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'silindi'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'E'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
   <span style="color: #339933;">-&gt;</span><span style="color: #004000;">where</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'bolum_id'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'='</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">12</span><span style="color: #009900;">&#41;</span>
   <span style="color: #339933;">-&gt;</span><span style="color: #004000;">execute</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// Sorgu: &quot;UPDATE personel SET silindi = 'E' WHERE bolum_id = 12&quot;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// DELETE işlemi</span>
DB<span style="color: #339933;">::</span><span style="color: #004000;">delete</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'personel'</span><span style="color: #009900;">&#41;</span>
   <span style="color: #339933;">-&gt;</span><span style="color: #004000;">where</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'bolum_id'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'='</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">12</span><span style="color: #009900;">&#41;</span>
   <span style="color: #339933;">-&gt;</span><span style="color: #004000;">execute</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// Sorgu: &quot;DELETE FROM personel WHERE bolum_id = 12&quot;</span></pre></div></div>

<img src="http://feeds.feedburner.com/~r/webgelistirici/~4/_jJ6JeUSe7c" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.webgelistirici.com/kohana-3-0-notlari-veritabani-kullanimi.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.webgelistirici.com/kohana-3-0-notlari-veritabani-kullanimi.html</feedburner:origLink></item>
		<item>
		<title>Controller-Model-View Tasarım Deseni (MVC Design Pattern)</title>
		<link>http://feedproxy.google.com/~r/webgelistirici/~3/1YeaVPwdJi8/controller-model-view-tasarim-deseni-design-pattern.html</link>
		<comments>http://www.webgelistirici.com/controller-model-view-tasarim-deseni-design-pattern.html#comments</comments>
		<pubDate>Thu, 14 Apr 2011 14:32:56 +0000</pubDate>
		<dc:creator>Bülent Yılmaz</dc:creator>
				<category><![CDATA[Diğer]]></category>
		<category><![CDATA[Kohana]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[controller]]></category>
		<category><![CDATA[model]]></category>
		<category><![CDATA[mvc]]></category>
		<category><![CDATA[view]]></category>

		<guid isPermaLink="false">http://www.webgelistirici.com/?p=244</guid>
		<description><![CDATA[Makale içeriğini görmek için lütfen makale başlığına tıklayınız.]]></description>
			<content:encoded><![CDATA[<p>Model-view-controller, yazılım mühendisliğinde kullanılan bir &#8220;<strong>mimari desen</strong>&#8220;dir. Karmaşık uygulamalarda, veri ve gösterimin soyutlanması esasına dayanır. Böylece &#8220;<strong>veri erişimi ve iş mantığı</strong>&#8221; (model katmanı) ile &#8220;<strong>veri gösterimi ve kullanıcı arayüzü</strong>&#8221; (view katmanı) birbirini etkilemeden düzenlenebilir. Tüm işleyişi, &#8220;<strong>controller</strong>&#8221; katmanı yönetir.</p>
<p><a href="http://www.webgelistirici.com/wp-content/uploads/mvc.gif"><img src="http://www.webgelistirici.com/wp-content/uploads/mvc.gif" alt="" title="Controller Model View" width="580" height="317" class="aligncenter size-full wp-image-248" /></a></p>
<p><span id="more-244"></span></p>
<h2>Controller</h2>
<p>Controller, sistemin karar mekanizmasıdır. Gelen talepleri kontrol eder ve sistemin diğer elemanlarının (model ve view) bilgiyi uygun şekilde alıp, göndermelerini sağlar.</p>
<h2>Model</h2>
<p>Model, iş mantığını ve veri işleme süreçlerini yürütür. Controller tarafından gönderilen emirlere göre hareket eder. Bilgi işleme sürecinden sonra veriyi Controller’a gönderir.</p>
<h2>View</h2>
<p>View, son kullanıcıya gösterilecek olan verinin sunumu ile ilgilenir. View, bu bilgiyi Controller&#8217;dan alır, aynı zamanda son kullanıcıdan gelen talepleri Controller&#8217;a iletir.</p>
<img src="http://feeds.feedburner.com/~r/webgelistirici/~4/1YeaVPwdJi8" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.webgelistirici.com/controller-model-view-tasarim-deseni-design-pattern.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.webgelistirici.com/controller-model-view-tasarim-deseni-design-pattern.html</feedburner:origLink></item>
		<item>
		<title>Kohana 3.0 Notları: View ve Şablon (Template) Kullanımı</title>
		<link>http://feedproxy.google.com/~r/webgelistirici/~3/IF9diSlWQhM/kohana-3-0-notlari-view-ve-sablon-template-kullanimi.html</link>
		<comments>http://www.webgelistirici.com/kohana-3-0-notlari-view-ve-sablon-template-kullanimi.html#comments</comments>
		<pubDate>Thu, 14 Apr 2011 08:00:14 +0000</pubDate>
		<dc:creator>Bülent Yılmaz</dc:creator>
				<category><![CDATA[Kohana]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[factory]]></category>
		<category><![CDATA[request]]></category>
		<category><![CDATA[response]]></category>
		<category><![CDATA[template]]></category>
		<category><![CDATA[view]]></category>

		<guid isPermaLink="false">http://www.webgelistirici.com/?p=231</guid>
		<description><![CDATA[Makale içeriğini görmek için lütfen makale başlığına tıklayınız.]]></description>
			<content:encoded><![CDATA[<h2>View nesnesini tanımlama</h2>
<p>Konum : &#8220;<code>application/views/v.php</code>&#8221;</p>
<p><strong>(1)</strong>  &#8220;<code>View</code>&#8221; sınıfının &#8220;<code>factory()</code>&#8221; statik yöntemi ile<br />
<code>View::factory('v')</code></p>
<p><strong>(2)</strong> Yapılandırıcı (<code>construct</code>) yöntem ile<br />
<code>new View('v')</code></p>
<p>Alt klasörde bulunan view dosyası için bir başka örnek;</p>
<p>Konum : &#8220;<code>application/views/alt1/alt2/v.php</code>&#8221;</p>
<p><code>View::factory('alt1/alt2/v')</code><br />
veya<br />
<code>new View('alt1/alt2/v')</code></p>
<p><span id="more-231"></span></p>
<h2>View ve Şablon (Template) kullanımı</h2>
<p>Konum : &#8220;<code>application/views/v.php</code>&#8221;</p>
<p><strong>(1)</strong> Ata sınıf <code>Controller_Template</code> ise, şablon (template) şöyle kullanılır;</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// Önce şablon nesnesi tanımlanır</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000088;">$template</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'v'</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Bu sınıf özelliği, metodların üstünde sınıf özelliği olarak tanımlanır</span>
&nbsp;
&nbsp;
<span style="color: #666666; font-style: italic;">// Sınıfın herhangi bir yöntemi içinde;</span>
&nbsp;
<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">template</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">bind</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'deger'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$degisken</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// veya</span>
<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">template</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">set</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'deger'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">5</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// veya</span>
<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">template</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">deger</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">5</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// set() yöntemi ile eşdeğer</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Şablon dosyasının içinde $deger değişkeni olarak kullanılır</span>
<span style="color: #666666; font-style: italic;">// Şablon içeriği otomatik ekrana yazılacaktır</span></pre></div></div>

<p>Yani değişkenler <code>bind()</code> yöntemi ile, değişmez (literal) değerler <code>set()</code> yöntemi ile atanır.</p>
<p><strong>(2)</strong> Ata sınıf <code>Contoller</code> ise, view şöyle kullanılır;</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// Önce view nesnesi tanımlanır</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000088;">$view_nesnesi</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Bu sınıf özelliği, metodların üstünde sınıf özelliği olarak tanımlanır</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Sınıfın herhangi bir yöntemi içinde;</span>
<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">view_nesnesi</span> <span style="color: #339933;">=</span> View<span style="color: #339933;">::</span><span style="color: #004000;">factory</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'v'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// View içine değer gönderelim</span>
<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">view_nesnesi</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">bind</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'deger'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$deger</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// veya</span>
<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">view_nesnesi</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">set</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'deger'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">5</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// View içeriğini ekrana yazdıralım</span>
&nbsp;
<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">request</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">response</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">view_nesnesi</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">render</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// HTML kodu üretilip atanır</span>
<span style="color: #666666; font-style: italic;">// veya</span>
<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">request</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">response</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">view_nesnesi</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// render() yöntemi kullanılmasa da otomatik render edilip atanır</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// View dosyasının içinde $deger değişkeni olarak kullanılır</span></pre></div></div>

<p>Burada da aynı şekilde, değişkenler <code>bind()</code> yöntemi ile, değişmez (literal) değerler <code>set()</code> yöntemi ile atanır.</p>
<p>View içine değerler dizi içinde toplanarak da gönderilebilir:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$parametreler</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'deger1'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">5</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$parametreler</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'deger2'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">request</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">response</span> <span style="color: #339933;">=</span> View<span style="color: #339933;">::</span><span style="color: #004000;">factory</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'v'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$parametreler</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// view içinde $deger1 ve $deger2 olarak kullanılır</span></pre></div></div>

<h2>View içinde view kullanımı</h2>
<p>Alt view konumu : &#8220;<code>application/views/alt1/v1.php</code>&#8221;</p>
<p>View içine değişkenle geçirilebilir veya view içinde <code>factory()</code> statik yöntemi ile doğrudan kullanılabilir:</p>
<p><strong>(1)</strong> View içine değişkenle geçirme;</p>
<p>Controller içinde iken;</p>
<p><strong>(1.a)</strong> Ata sınıf <code>Controller_Template</code> ise;</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">template</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">v1</span> <span style="color: #339933;">=</span> View<span style="color: #339933;">::</span><span style="color: #004000;">factory</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'alt1/v1'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Şablon dosyasının içinde;</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">echo</span> <span style="color: #000088;">$v1</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// şeklinde çağrılır</span></pre></div></div>

<p><strong>(1.b)</strong> Ata sınıf <code>Controller</code> ise;</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">view_nesnesi</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">set</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'v1'</span><span style="color: #339933;">,</span> View<span style="color: #339933;">::</span><span style="color: #004000;">factory</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'alt1/v1'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Ana view dosyasının içinde;</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">echo</span> <span style="color: #000088;">$v1</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// şeklinde çağrılır</span></pre></div></div>

<p><strong>(2)</strong> Ana view içinde <code>factory()</code> yöntemi ile kullanma;</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">echo</span> View<span style="color: #339933;">::</span><span style="color: #004000;">factory</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'alt1/v1'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">render</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// HTML içerik üretilip ekrana basılıyor</span></pre></div></div>

<img src="http://feeds.feedburner.com/~r/webgelistirici/~4/IF9diSlWQhM" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.webgelistirici.com/kohana-3-0-notlari-view-ve-sablon-template-kullanimi.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.webgelistirici.com/kohana-3-0-notlari-view-ve-sablon-template-kullanimi.html</feedburner:origLink></item>
		<item>
		<title>Kohana 3.0 Notları: Model Kullanımı</title>
		<link>http://feedproxy.google.com/~r/webgelistirici/~3/_m_GjPGmzcc/kohana-3-0-notlari-model-kullanimi.html</link>
		<comments>http://www.webgelistirici.com/kohana-3-0-notlari-model-kullanimi.html#comments</comments>
		<pubDate>Wed, 13 Apr 2011 09:21:14 +0000</pubDate>
		<dc:creator>Bülent Yılmaz</dc:creator>
				<category><![CDATA[Kohana]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[factory]]></category>
		<category><![CDATA[model]]></category>

		<guid isPermaLink="false">http://www.webgelistirici.com/?p=209</guid>
		<description><![CDATA[Makale içeriğini görmek için lütfen makale başlığına tıklayınız.]]></description>
			<content:encoded><![CDATA[<h2>Model sınıfını tanımlama</h2>
<p>Konum : &#8220;<code>application/classes/model/ornek.php</code>&#8221;</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> Model_Ornek <span style="color: #000000; font-weight: bold;">extends</span> Model <span style="color: #666666; font-style: italic;">// Sınıf adlandırması standarda göre yapılır (hiyerarşi belirtiyor)</span>
<span style="color: #009900;">&#123;</span>
   <span style="color: #666666; font-style: italic;">// Özellik ve yöntemler</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Alt klasörde bulunan model dosyası için bir başka örnek;</p>
<p>Konum : &#8220;<code>application/classes/model/proje/deneme.php</code>&#8221;</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> Model_Proje_Deneme <span style="color: #000000; font-weight: bold;">extends</span> Model <span style="color: #666666; font-style: italic;">// Sınıf adlandırması standarda göre yapılır (hiyerarşi belirtiyor)</span>
<span style="color: #009900;">&#123;</span>
   <span style="color: #666666; font-style: italic;">// Özellik ve yöntemler</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Görüldüğü gibi model sınıfları, <code>Model</code> sınıfından kalıtılır.</p>
<p><span id="more-209"></span></p>
<h2>Model nesnesini tanımlama</h2>
<p>Controller içinde model nesnesi 2 şekilde tanımlanır:</p>
<p>Örneğin, &#8220;<code>application/classes/model/proje/deneme.php</code>&#8221; dosyasında tanımlı &#8220;<code>Model_Proje_Deneme</code>&#8221; model sınıfı için;</p>
<p><strong>(1)</strong> &#8220;<code>Model</code>&#8221; sınıfının &#8220;<code>factory()</code>&#8221; statik yöntemi ile;</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// Controller sınıfının içinde iken, bu sınıfın $model_nesnesi özelliğine atayalım</span>
<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">model_nesnesi</span> <span style="color: #339933;">=</span> Model<span style="color: #339933;">::</span><span style="color: #004000;">factory</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'proje_deneme'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
<span style="color: #666666; font-style: italic;">// &quot;model/&quot; dizini sonrasından itibaren yazılır, hiyerarşi alt çizgi ile belirtilir</span></pre></div></div>

<p><strong>(2)</strong> Sınıf adı ile;</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// Controller sınıfının içinde iken, bu sınıfın $model_nesnesi özelliğine atayalım</span>
<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">model_nesnesi</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Model_Proje_Deneme<span style="color: #339933;">;</span></pre></div></div>

<img src="http://feeds.feedburner.com/~r/webgelistirici/~4/_m_GjPGmzcc" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.webgelistirici.com/kohana-3-0-notlari-model-kullanimi.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.webgelistirici.com/kohana-3-0-notlari-model-kullanimi.html</feedburner:origLink></item>
		<item>
		<title>Kohana 3.0 Notları: Controller Kullanımı</title>
		<link>http://feedproxy.google.com/~r/webgelistirici/~3/zOxa8cWyqaM/kohana-3-0-notlari-controller-kullanimi.html</link>
		<comments>http://www.webgelistirici.com/kohana-3-0-notlari-controller-kullanimi.html#comments</comments>
		<pubDate>Tue, 12 Apr 2011 14:29:00 +0000</pubDate>
		<dc:creator>Bülent Yılmaz</dc:creator>
				<category><![CDATA[Kohana]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[after]]></category>
		<category><![CDATA[before]]></category>
		<category><![CDATA[controller]]></category>
		<category><![CDATA[controller_template]]></category>

		<guid isPermaLink="false">http://www.webgelistirici.com/?p=190</guid>
		<description><![CDATA[Makale içeriğini görmek için lütfen makale başlığına tıklayınız.]]></description>
			<content:encoded><![CDATA[<h2>Controller sınıfını tanımlama</h2>
<p><span style="text-decoration: underline;"><strong>Örnek:</strong></span><br />
konum : &#8220;<code>application/classes/controller/ornek.php</code>&#8221; içinde tanımlı &#8220;<code>Controller_Ornek</code>&#8221; sınıfı 2 şekilde tanımlanabilir:</p>
<p><strong>(1)</strong> <code>class Controller_Ornek extends <strong>Controller_Template</strong></code><br />
<strong>(2)</strong> <code>class Controller_Ornek extends <strong>Controller</strong></code></p>
<p>URL: <code>http://localhost/kohana/ornek</code></p>
<p><span style="text-decoration: underline;"><strong>Örnek:</strong></span><br />
konum : &#8220;<code>application/classes/controller/ornek.php</code>&#8221; içinde tanımlı &#8220;<code>Controller_Ornek</code>&#8221; sınıfı</p>
<p><strong>(1)</strong></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> Controller_Ornek <span style="color: #000000; font-weight: bold;">extends</span> Controller_Template
<span style="color: #009900;">&#123;</span>
   <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000088;">$template</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'v'</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// view konumu : &quot;application/views/v.php&quot;</span>
&nbsp;
   <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> action_index<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #666666; font-style: italic;">// varsayılan yöntem</span>
   <span style="color: #009900;">&#123;</span>
       <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">template</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">deger</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;selam&quot;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Ata sınıf &quot;Controller_Template&quot; ise şablona bu şekilde değer gönderilir</span>
       <span style="color: #666666; font-style: italic;">// Şablon içinde $deger değişkeni &quot;selam&quot; değerini tutar</span>
   <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p><strong>(2)</strong></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> Controller_Ornek <span style="color: #000000; font-weight: bold;">extends</span> Controller
<span style="color: #009900;">&#123;</span>
   <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> action_index<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
   <span style="color: #009900;">&#123;</span>
       <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">request</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">response</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;selam&quot;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Ata sınıf &quot;Controller&quot; olduğu durumda ekrana yazılacak değer bu şekilde atanır.</span>
   <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p><span id="more-190"></span></p>
<h2>Controller içindeki yöntemler</h2>
<p>Controller içindeki tüm yöntemlerin isimleri, &#8220;<code><strong>action_</strong></code>&#8221; ile başlayacak şekilde tanımlanır.<br />
<code>action_listele()<br />
action_veri_ekle()</code><br />
gibi&#8230;</p>
<p>Controller içindeki varsayılan yöntem &#8220;<code>action_index()</code>&#8221; yöntemidir. Yani controller adı yazılıp yöntem adı belirtilmezse, doğrudan bu yöntem çalışır.<br />
<code>function <strong>action_index</strong>()<br />
{ ... }</code></p>
<h2>before() ve after() metodları</h2>
<p>Controller veya model sınıflarında kullanılabilirler. (Zorunlu değil)</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> before<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
   parent<span style="color: #339933;">::</span><span style="color: #004000;">before</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Mutlaka yazılmalı!</span>
&nbsp;
   <span style="color: #666666; font-style: italic;">// Model ve view nesnelerinin tanımlanması gibi ilk işlemler yapılır</span>
   <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">model1</span> <span style="color: #339933;">=</span> Model<span style="color: #339933;">::</span><span style="color: #004000;">factory</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'dizin_m'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// konum : &quot;application/model/dizin/m.php&quot;</span>
   <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">view1</span> <span style="color: #339933;">=</span> View<span style="color: #339933;">::</span><span style="color: #004000;">factory</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'dizin/v'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// konum : &quot;application/views/dizin/v.php&quot;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>before() yerine aşağıdaki gibi bir kullanım da mümkündür;</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __construct<span style="color: #009900;">&#40;</span>Request <span style="color: #000088;">$request</span><span style="color: #009900;">&#41;</span> <span style="color: #666666; font-style: italic;">// before() metodu yerine kullanılabilir</span>
<span style="color: #009900;">&#123;</span>
   parent<span style="color: #339933;">::</span>__construct<span style="color: #009900;">&#40;</span><span style="color: #000088;">$request</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Mutlaka yazılmalı!</span>
&nbsp;
   <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">model1</span> <span style="color: #339933;">=</span> Model<span style="color: #339933;">::</span><span style="color: #004000;">factory</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'dizin_m'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// konum : &quot;application/model/dizin/m.php&quot;</span>
   <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">view1</span> <span style="color: #339933;">=</span> View<span style="color: #339933;">::</span><span style="color: #004000;">factory</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'dizin/v'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// konum : &quot;application/views/dizin/v.php&quot;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p><code>after()</code> yöntemi de <code>before()</code> yöntemi gibi kullanılır;</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> after<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
   parent<span style="color: #339933;">::</span><span style="color: #004000;">after</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Mutlaka yazılmalı!</span>
&nbsp;
   <span style="color: #666666; font-style: italic;">// Veritabanı sonlandırma gibi işlemler</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<img src="http://feeds.feedburner.com/~r/webgelistirici/~4/zOxa8cWyqaM" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.webgelistirici.com/kohana-3-0-notlari-controller-kullanimi.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.webgelistirici.com/kohana-3-0-notlari-controller-kullanimi.html</feedburner:origLink></item>
		<item>
		<title>Kohana 3.0 Notları: Temeller</title>
		<link>http://feedproxy.google.com/~r/webgelistirici/~3/E4r9LhmCCI4/kohana-3-0-notlari-temeller.html</link>
		<comments>http://www.webgelistirici.com/kohana-3-0-notlari-temeller.html#comments</comments>
		<pubDate>Tue, 12 Apr 2011 07:35:45 +0000</pubDate>
		<dc:creator>Bülent Yılmaz</dc:creator>
				<category><![CDATA[Kohana]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[autoload]]></category>
		<category><![CDATA[class]]></category>
		<category><![CDATA[redirect]]></category>
		<category><![CDATA[rewrite url]]></category>
		<category><![CDATA[stats]]></category>

		<guid isPermaLink="false">http://www.webgelistirici.com/?p=164</guid>
		<description><![CDATA[Makale içeriğini görmek için lütfen makale başlığına tıklayınız.]]></description>
			<content:encoded><![CDATA[<h2>Kurulum sonrası &#8220;Rewrite URL&#8221; ayarı</h2>
<p><code>http://localhost/kohana/index.php/test</code><br />
şeklinde değil de<br />
<code>http://localhost/kohana/test</code><br />
şeklinde &#8220;<code>index.php/</code>&#8221; yani <strong>front controller</strong> yazılmadan çalışması için;<br />
Kohana kök dizinindeki &#8220;<code>example.htaccess</code>&#8221; dosyasının adı &#8220;<code>.htaccess</code>&#8221; olarak değiştirilir.</p>
<p>Ayrıca bu dosyanın içeriğinde aşağıdaki değişiklik yapılmalıdır;<br />
<code># Installation directory<br />
<strong>RewriteBase /kohana/</strong></code><br />
şeklinde değiştirilir.</p>
<p><span id="more-164"></span></p>
<h2>Sınıfları isimlendirme</h2>
<ul>
<li>Adlandırma &#8220;<code>classes/</code>&#8221; sonrasından itibaren başlar</li>
<li>Sınıf ismindeki kelimeler &#8220;<code>_</code>&#8221; ile ayrılır ve bu hiyerarşiyi bildirir</li>
<li>Sınıf ismindeki kelimelerin ilk harfleri büyüktür</li>
</ul>
<p><span style="text-decoration: underline;"><strong>Örnekler:</strong></span></p>
<p>konum : <code>classes/session/cookie.php</code><br />
sınıf adı: <code><strong>Session_Cookie</strong></code></p>
<p>konum : <code>classes/controller/template.php</code><br />
sınıf adı: <code><strong>Controller_Template</strong></code></p>
<h2>Sınıfları Otomatik Yükletme (Autoload)</h2>
<p>Sınıfın tanımlı olduğu dosya &#8220;<code>classes/</code>&#8221; altına konur ve sınıf isimlendirmesi standarda göre yapılır;</p>
<p>konum: <code>classes/<strong>sinif</strong>/<strong>kutu</strong>.php</code></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> Sinif_Kutu <span style="color: #666666; font-style: italic;">// Standarda göre</span>
<span style="color: #009900;">&#123;</span>
   <span style="color: #000000; font-weight: bold;">public</span> static <span style="color: #000088;">$x</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">5</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Herhangi bir yerde kullanırken, sınıf tanımlamaya gerek olmadan doğrudan kullanılır;</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">echo</span> Sinif_Kutu<span style="color: #339933;">::</span><span style="color: #000088;">$x</span><span style="color: #339933;">;</span></pre></div></div>

<p>Sınıf isimlendirmesi standarda göre yapılmamışsa, sınıfı kullanmadan önce <code>Kohana::auto_load()</code> yöntemi ile yüklemek gerekir.</p>
<p>konum: <code>classes/sinif/kutu.php</code> (&#8220;<code>classes/</code>&#8221; altında olmalıdır)</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> kutu <span style="color: #666666; font-style: italic;">// Sınıf ismi standarda göre değil (hiyerarşi belirtmiyor)</span>
<span style="color: #009900;">&#123;</span>
   <span style="color: #000000; font-weight: bold;">public</span> static <span style="color: #000088;">$x</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">5</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Herhangi bir yerde kullanırken, önce sınıf çağrılır;</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">Kohana<span style="color: #339933;">::</span><span style="color: #004000;">auto_load</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Sinif_Kutu'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Sınıfı çağır</span>
<span style="color: #b1b100;">echo</span> kutu<span style="color: #339933;">::</span><span style="color: #000088;">$x</span><span style="color: #339933;">;</span></pre></div></div>

<h2>Hiyerarşik yapı</h2>
<p><code>application/classes/<strong>controller</strong>/...<br />
application/classes/<strong>model</strong>/...<br />
application/<strong>views</strong>/...</p>
<p>modules/...</p>
<p>system/...</code></p>
<p><code>system</code> klasörü; kohana çekirdeği ve kütüphane dosyaları, öntanımlı yapılandırma dosyaları ve yardımcılar (helpers) gibi kohana araçlarını içerir.</p>
<h2>Tüm dosyaların ilk satırı</h2>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #990000;">defined</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'SYSPATH'</span><span style="color: #009900;">&#41;</span> OR <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'No direct access allowed.'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Bütün istekler &#8220;<code>index.php</code>&#8221; (front controller) üzerinden gerçekleşir. Diğer hiçbir dosyaya doğrudan erişilemez.</p>
<h2>Uygulama istatistiklerini görme</h2>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">View<span style="color: #339933;">::</span><span style="color: #004000;">factory</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'profiler/stats'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<h2>Hata yakalamayı devre dışı bırakma</h2>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">Kohana<span style="color: #339933;">::</span><span style="color: #004000;">init</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'errors'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">FALSE</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<h2>URL Yönlendirme</h2>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">request</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">redirect</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'test'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
<span style="color: #666666; font-style: italic;">// http://localhost/kohana/test adresine yönlenir</span>
<span style="color: #666666; font-style: italic;">// veya</span>
<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">request</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">redirect</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'http://localhost/kohana/test'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
<span style="color: #666666; font-style: italic;">// yönlenilecek tam yol yazılır</span></pre></div></div>

<img src="http://feeds.feedburner.com/~r/webgelistirici/~4/E4r9LhmCCI4" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.webgelistirici.com/kohana-3-0-notlari-temeller.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.webgelistirici.com/kohana-3-0-notlari-temeller.html</feedburner:origLink></item>
		<item>
		<title>Kohana 3.0 Notları: Kohana’da URI ve Rota (Route) Yapısı</title>
		<link>http://feedproxy.google.com/~r/webgelistirici/~3/WdnNjcqOJDo/kohana-3-0-notlari-kohanada-uri-ve-rota-route-yapisi.html</link>
		<comments>http://www.webgelistirici.com/kohana-3-0-notlari-kohanada-uri-ve-rota-route-yapisi.html#comments</comments>
		<pubDate>Mon, 11 Apr 2011 10:24:08 +0000</pubDate>
		<dc:creator>Bülent Yılmaz</dc:creator>
				<category><![CDATA[Kohana]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[route]]></category>

		<guid isPermaLink="false">http://www.webgelistirici.com/?p=104</guid>
		<description><![CDATA[Makale içeriğini görmek için lütfen makale başlığına tıklayınız.]]></description>
			<content:encoded><![CDATA[<p>Kohana&#8217;da URI çözümlemesi, rota (route) tanımlamalarına göre yapılır. Böylece <strong>controller</strong>, <strong>yöntem</strong> ve <strong>parametre</strong>nin otomatik olarak ayrıştırılması sağlanır.</p>
<p><span style="text-decoration: underline;"><strong>Örnek:</strong></span><br />
URI: <code>http://localhost/kohana/index.php/test/goster/1</code></p>
<ul>
<li>Front controller: &#8220;<code>index.php</code>&#8220;</li>
<li>Controller: &#8220;<code>test</code>&#8220;</li>
<li>Yöntem: &#8220;<code>goster</code>&#8220;</li>
<li>Parametre: <code>1</code></li>
</ul>
<p>Tüm istekler front controller üzerinden gerçekleşir. &#8220;Rewrite url&#8221; ayarı yapılmışsa kısaca front controller kullanmadan da kullanılabilir;</p>
<p><code>http://localhost/kohana/test/goster/1</code></p>
<p>Ayrıca &#8220;?&#8221; operatörü ile en sona GET parametreleri de yazılabilir</p>
<p><code>http://localhost/kohana/test/goster/1?x=3&amp;y=5</code></p>
<p><span id="more-104"></span></p>
<h2>Rota tanımlama</h2>
<p>Rota tanımlamaları &#8220;<code>application/bootstrap.php</code>&#8221; dosyası içinde tanımlanır:</p>
<p><code><strong>Route::set(rota_ismi, rota[, duzenli_ifade]);</strong></code></p>
<p><span style="text-decoration: underline;"><strong>Örnek:</strong></span><br />
<code>// Kohana'nın varsayılan rota tanımı<br />
Route::set('default', '((/(/)))', array())</code></p>
<p>Rota içinde geçen &#8220;controller&#8221;, &#8220;action&#8221;, &#8220;id&#8221; kelimeleri, rota anahtarları olarak adlandırılır. Ayrıca bunların dışında bir de alt klasördeki controller dosyalarını tanımlamaya yarayan &#8220;directory&#8221; rota anahtarı vardır.</p>
<p>Rota anahtarları &#8220;<code>&lt;</code>&#8221; ve &#8220;<code>&gt;</code>&#8221; arasında olmalıdır. Parantezler içinde olması, seçimlik olduğunu ifade eder.</p>
<h2>Rota anahtarları için varsayılan değer tanımlama</h2>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">Route<span style="color: #339933;">::</span><span style="color: #004000;">set</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'default'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'((/(/)))'</span><span style="color: #009900;">&#41;</span>
   <span style="color: #339933;">-&gt;</span><span style="color: #004000;">defaults</span><span style="color: #009900;">&#40;</span>
      <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
         <span style="color: #0000ff;">'controller'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'test'</span><span style="color: #339933;">,</span> <span style="color: #666666; font-style: italic;">/* varsayılan controller */</span>
         <span style="color: #0000ff;">'action'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'index'</span><span style="color: #339933;">,</span> <span style="color: #666666; font-style: italic;">/* varsayılan yöntem */</span>
         <span style="color: #0000ff;">'id'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">1</span> <span style="color: #666666; font-style: italic;">/* varsayılan parametre */</span>
      <span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Bu durumda;<br />
<code>http://localhost/kohana/ ⇔ http://localhost/kohana/test/index/1<br />
// Bu durumda ikisi de aynı olur</code></p>
<h2>Alt klasördeki controller için rota tanımı</h2>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">Route<span style="color: #339933;">::</span><span style="color: #004000;">set</span><span style="color: #009900;">&#40;</span>
   <span style="color: #0000ff;">'altklasor'</span><span style="color: #339933;">,</span>
   <span style="color: #0000ff;">'&lt;directory&gt;(/&lt;controller&gt;(/&lt;action&gt;(/&lt;id&gt;)))'</span><span style="color: #339933;">,</span>
   <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
      <span style="color: #0000ff;">'directory'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'(alt1(/(alt2))|alt1)'</span><span style="color: #009900;">&#41;</span>
   <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// Alt klasör daha önce tanımlanmalı (yani alt2, alt1'den daha önce tanımlanmalı)</span></pre></div></div>

<p><span style="text-decoration: underline;"><strong>Örnek:</strong></span><br />
<code>http://localhost/kohana/alt1/alt2/test<br />
// controller : alt1/alt2/test</code></p>
<h2>Rota anahtarları için düzenli ifade tanımlama</h2>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">Route<span style="color: #339933;">::</span><span style="color: #004000;">set</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'default'</span><span style="color: #339933;">,</span>
   <span style="color: #0000ff;">'(&lt;controller&gt;(/&lt;action&gt;(/&lt;id&gt;)))'</span><span style="color: #339933;">,</span>
   <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'id'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'[0-9a-zA-Z]{1}'</span><span style="color: #009900;">&#41;</span> <span style="color: #666666; font-style: italic;">/* Parametre 1 basamaklı rakam veya alfabetik karakter olabilir anlamına geliyor */</span>
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Aynı isme sahip birden fazla rota tanımlanırsa, öncelik sırasına göre ilk eşleşen rota geçerli olur.</p>
<p>Kullanıcı tanımlı tüm rotalar Kohana&#8217;nın &#8220;<strong>default</strong>&#8221; isimli rotasından önce tanımlanmalıdır.</p>
<p>Bir URI isteği geldiğinde sırayla uygun olan ilk rota işleme alınır ve sonraki rotalara bakılmaz. Hiçbir rota ile işleşme bulunamazsa &#8220;default&#8221; isimli rota geçerli olur.</p>
<p><span style="text-decoration: underline;"><strong>Örnek:</strong></span> Bir URI&#8217;nin tanımlı rotalara uygunluğunu test etme</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$uri</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'http://localhost/kohana/test'</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Test edilecek URI</span>
<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span>Route<span style="color: #339933;">::</span><span style="color: #004000;">all</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$rota</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
   <span style="color: #b1b100;">echo</span> Kohana<span style="color: #339933;">::</span><span style="color: #004000;">debug</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$rota</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">matches</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$uri</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #666666; font-style: italic;">// Eşleşmeyen rotalar yerine FALSE, eşleşen rotalarda ise</span>
   <span style="color: #666666; font-style: italic;">// path, controller, action ve içeriklerinden oluşan bir dizi yazar</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p><span style="text-decoration: underline;"><strong>Örnek:</strong></span></p>
<p>URI : <code>http://localhost/kohana/test</code></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;pre&gt;'</span> <span style="color: #339933;">.</span> <span style="color: #990000;">print_r</span><span style="color: #009900;">&#40;</span>Request<span style="color: #339933;">::</span><span style="color: #004000;">instance</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">TRUE</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&lt;/pre&gt;'</span><span style="color: #339933;">;</span></pre></div></div>

<p><span style="text-decoration: underline;"><strong>Örnek:</strong></span></p>
<p>URI : <code>http://localhost/kohana/test</code></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">echo</span> Request<span style="color: #339933;">::</span><span style="color: #004000;">instance</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">controller</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Çıktı : test</span></pre></div></div>

<p>Kohana&#8217;da rota işlemleriyle ilgili bir başka makaleye <a href="http://www.eburhan.com/kohana-frameworkunde-routing-islemleri/" target="_blank">şu adresten</a> ulaşabilirsiniz.</p>
<img src="http://feeds.feedburner.com/~r/webgelistirici/~4/WdnNjcqOJDo" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.webgelistirici.com/kohana-3-0-notlari-kohanada-uri-ve-rota-route-yapisi.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://www.webgelistirici.com/kohana-3-0-notlari-kohanada-uri-ve-rota-route-yapisi.html</feedburner:origLink></item>
		<item>
		<title>MARQUEE Elementi ile Basit Kayma Efekti Oluşturmak</title>
		<link>http://feedproxy.google.com/~r/webgelistirici/~3/bOKxJSl7ZOs/marquee-elementi-ile-basit-kayma-efekti.html</link>
		<comments>http://www.webgelistirici.com/marquee-elementi-ile-basit-kayma-efekti.html#comments</comments>
		<pubDate>Sun, 14 Feb 2010 07:55:22 +0000</pubDate>
		<dc:creator>Bülent Yılmaz</dc:creator>
				<category><![CDATA[HTML / XHTML]]></category>
		<category><![CDATA[marquee]]></category>

		<guid isPermaLink="false">http://www.webgelistirici.com/?p=39</guid>
		<description><![CDATA[Makale içeriğini görmek için lütfen makale başlığına tıklayınız.]]></description>
			<content:encoded><![CDATA[<p><!-- 		@page { margin: 2cm } 		P { margin-bottom: 0.21cm } 		A:link { so-language: zxx } -->HTML&#8217;in <code>&lt;marquee&gt;</code> elementi ile JavaScript, Flash gibi başka bir teknolojiye gerek duymadan basitçe kayan yazı veya resim efekti oluşturabiliriz. Bu element <code>span</code> ya da <code>img</code> elementleri gibi bir satır içi (inline) elementtir.</p>
<p>Örnek kullanımları;</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;marquee scrollamount<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;5&quot;</span> behavior<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;scroll&quot;</span> direction<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;left&quot;</span> <span style="color: #000066;">style</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;background-color: #FAFAA0; width: 200px;&quot;</span>&gt;</span>webgelistirici.com<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span>marquee&gt;</span></pre></div></div>

<div align="center" style="margin-bottom: 15px;"><marquee scrollamount="5" behavior="scroll" direction="left" style="background-color: #FAFAA0; width: 200px;">webgelistirici.com</marquee></div>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;marquee scrollamount<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;5&quot;</span> behavior<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;alternate&quot;</span> direction<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;left&quot;</span> <span style="color: #000066;">style</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;background-color: #FAFAA0; width: 200px;&quot;</span>&gt;</span>webgelistirici.com<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span>marquee&gt;</span></pre></div></div>

<div align="center"><marquee scrollamount="5" behavior="alternate" direction="left" style="background-color: #FAFAA0; width: 200px;">webgelistirici.com</marquee></div>
<p><code>scrollamount</code> niteliğinin değeri ne kadar büyük olursa metin o kadar hızlı kayar.</p>
<p><code>behavior</code> niteliğinin <code>altenate</code> olması sağa-sola kaymayı, <code>slide</code> olması <code>loop</code> niteliğinde verilen sayı kadar kaymanın tekrarlanacağını, <code>scroll</code> olması kaymanın sürekli tekrarlanacağını ifade eder.</p>
<p><code>&lt;marquee&gt;</code> elementi ayrıca <code>&lt;img/&gt;</code> elementinde de kullanılabilen <code>width, height, hspace, vspace, align</code> niteliklerini de destekler.</p>
<p>İnternette tüm özelliklerini bir arayüzden seçebilmemize olanak veren <strong>HTML Marquee Generator</strong> araçları mevcuttur. Örneğin <a href="http://www.quackit.com/html/html_generators/html_marquee_generator.cfm" target="_blank">şu adreste</a> bir tane mevcut.</p>
<img src="http://feeds.feedburner.com/~r/webgelistirici/~4/bOKxJSl7ZOs" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.webgelistirici.com/marquee-elementi-ile-basit-kayma-efekti.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.webgelistirici.com/marquee-elementi-ile-basit-kayma-efekti.html</feedburner:origLink></item>
		<item>
		<title>Dizi Elemanlarını Biçimli Olarak Görüntülemek</title>
		<link>http://feedproxy.google.com/~r/webgelistirici/~3/a-2r4ly6-ig/dizi-elemanlarini-formatli-olarak-goruntulemek.html</link>
		<comments>http://www.webgelistirici.com/dizi-elemanlarini-formatli-olarak-goruntulemek.html#comments</comments>
		<pubDate>Sun, 14 Feb 2010 07:49:14 +0000</pubDate>
		<dc:creator>Bülent Yılmaz</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[dizi]]></category>
		<category><![CDATA[print_r]]></category>

		<guid isPermaLink="false">http://www.webgelistirici.com/?p=35</guid>
		<description><![CDATA[Makale içeriğini görmek için lütfen makale başlığına tıklayınız.]]></description>
			<content:encoded><![CDATA[<p>PHP&#8217;nin <code>print_r()</code> fonksiyonu bir dizinin içeriğini ekranda görüntülemeye yarar. Bazen program geliştirirken bir dizinin o anki içeriğini öğrenmek isteriz. Bu durumda diziyi döngü içinde kullanıp her bir elemanını ayrı ayrı yazdırmak yerine doğrudan bu komutu kullanabiliriz.</p>
<p>Bu komutu kullandığımızda, HTML birden fazla boşluğu tek boşluğa indirgediği için tüm dizi içeriği yan yana gösterilecektir. Eleman sayısı fazla olan dizilerde bu ifadenin okunması ve anlaşılması zor olacaktır.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$dizi</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'a'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'b'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'c'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">print_r</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dizi</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Bu fonksiyonu HTML&#8217;in <code>&lt;pre&gt;</code> elementi içinde kullanırsak tüm boşluklar olduğu gibi bırakılır ve dizi içeriği okunup anlaşılması daha kolay bir şekilde görüntülenir.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;pre&gt;'</span><span style="color: #339933;">;</span>
<span style="color: #990000;">print_r</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dizi</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;/pre&gt;'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// veya</span>
&nbsp;
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;pre&gt;'</span> <span style="color: #339933;">.</span> <span style="color: #990000;">print_r</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dizi</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">TRUE</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&lt;/pre&gt;'</span><span style="color: #339933;">;</span></pre></div></div>

<img src="http://feeds.feedburner.com/~r/webgelistirici/~4/a-2r4ly6-ig" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.webgelistirici.com/dizi-elemanlarini-formatli-olarak-goruntulemek.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.webgelistirici.com/dizi-elemanlarini-formatli-olarak-goruntulemek.html</feedburner:origLink></item>
		<item>
		<title>Farklı Tarayıcılar İçin Farklı JavaScript Harici Dosyası Kullanmak</title>
		<link>http://feedproxy.google.com/~r/webgelistirici/~3/tYfLa7qdbZ8/farkli-tarayicilar-icin-farkli-javascript-harici-dosyasi-yuklemek.html</link>
		<comments>http://www.webgelistirici.com/farkli-tarayicilar-icin-farkli-javascript-harici-dosyasi-yuklemek.html#comments</comments>
		<pubDate>Sun, 14 Feb 2010 07:37:07 +0000</pubDate>
		<dc:creator>Bülent Yılmaz</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[harici]]></category>

		<guid isPermaLink="false">http://www.webgelistirici.com/?p=29</guid>
		<description><![CDATA[Makale içeriğini görmek için lütfen makale başlığına tıklayınız.]]></description>
			<content:encoded><![CDATA[<p><!-- 		@page { margin: 2cm } 		P { margin-bottom: 0.21cm } -->Sayfamızda kullanacağımız JavaScript kodlarını harici bir dosyada toplayabiliriz. Bu durumda bu kodları <code>&lt;script src="dosya.js" type="text/javascript"&gt;</code> şeklinde sayfamıza ekleriz.</p>
<p>Tarayıcı türümüze özel kodlarımızı ayrı dosyalarda toplayıp, sadece ilgili tarayıcı için gerekli kodları yükletmek istersek şu yöntemi kullanabiliriz.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>document.<span style="color: #660066;">all</span><span style="color: #009900;">&#41;</span> <span style="color: #006600; font-style: italic;">// Internet Explorer için</span>
<span style="color: #009900;">&#123;</span>
   document.<span style="color: #000066; font-weight: bold;">write</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;script src=&quot;ie.js&quot; type=&quot;text/javascript&quot;&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000066; font-weight: bold;">else</span> <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>document.<span style="color: #660066;">style</span><span style="color: #009900;">&#41;</span> <span style="color: #006600; font-style: italic;">// Firefox için</span>
<span style="color: #009900;">&#123;</span>
   document.<span style="color: #000066; font-weight: bold;">write</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;script src=&quot;ff.js&quot; type=&quot;text/javascript&quot;&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Burada özellik algılama tekniğini kullanarak tarayıcı türünü öğrendik ve uygun harici JavaScript dosyasını sayfamıza dahil ettik. Tarayıcı türünü tespit etmek için <code>navigator.userAgent</code> ile elde edilen metindeki bilgiler de kullanılabilirdi. Ayrıca JavaScript&#8217;te <code>write()</code> fonksiyonu içine bu şekilde HTML kodları gömmek mümkündür.</p>
<img src="http://feeds.feedburner.com/~r/webgelistirici/~4/tYfLa7qdbZ8" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.webgelistirici.com/farkli-tarayicilar-icin-farkli-javascript-harici-dosyasi-yuklemek.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.webgelistirici.com/farkli-tarayicilar-icin-farkli-javascript-harici-dosyasi-yuklemek.html</feedburner:origLink></item>
		<item>
		<title>MySQL’de Sorgu İçine Açıklama Yazmak</title>
		<link>http://feedproxy.google.com/~r/webgelistirici/~3/_Xnw2zaxVmM/mysql-sorgusunun-icine-aciklama-yazmak.html</link>
		<comments>http://www.webgelistirici.com/mysql-sorgusunun-icine-aciklama-yazmak.html#comments</comments>
		<pubDate>Sun, 14 Feb 2010 07:27:01 +0000</pubDate>
		<dc:creator>Bülent Yılmaz</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[açıklama]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[yorum]]></category>

		<guid isPermaLink="false">http://www.webgelistirici.com/?p=26</guid>
		<description><![CDATA[Makale içeriğini görmek için lütfen makale başlığına tıklayınız.]]></description>
			<content:encoded><![CDATA[<p><!-- 		@page { margin: 2cm } 		P { margin-bottom: 0.21cm } -->Programlama dillerinde açıklamalar eklemek için çeşitli yapılar bulunur. Örneğin PHP&#8217;de tek satırlık ve çok satırlık açıklamalar şu şekilde kullanılır.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// tek satırlık açıklama</span>
<span style="color: #666666; font-style: italic;">/*
çok
satırlık
açıklama
*/</span></pre></div></div>

<p>MySQL sorguları içinde de benzer şekilde açıklamalar kullanmak mümkündür.</p>

<div class="wp_syntax"><div class="code"><pre class="mysql" style="font-family:monospace;"><span style="color: #990099; font-weight: bold;">SELECT</span> <span style="color: #CC0099;">*</span> <span style="color: #990099; font-weight: bold;">FROM</span> personel <span style="color: #990099; font-weight: bold;">WHERE</span> departman_id <span style="color: #CC0099;">=</span> <span style="color: #008080;">5</span> <span style="color: #808000; font-style: italic;">/* 5 : Muhasebe */</span> <span style="color: #CC0099; font-weight: bold;">OR</span> departman_id <span style="color: #CC0099;">=</span> <span style="color: #008080;">8</span> <span style="color: #808000; font-style: italic;">/* 8 : İnsan Kaynakları */</span></pre></div></div>

<p>Bu sorgu aşağıdaki sorgu ile eşdeğerdir.</p>

<div class="wp_syntax"><div class="code"><pre class="mysql" style="font-family:monospace;"><span style="color: #990099; font-weight: bold;">SELECT</span> <span style="color: #CC0099;">*</span> <span style="color: #990099; font-weight: bold;">FROM</span> personel <span style="color: #990099; font-weight: bold;">WHERE</span> departman_id <span style="color: #CC0099;">=</span> <span style="color: #008080;">5</span> <span style="color: #CC0099; font-weight: bold;">OR</span> departman_id <span style="color: #CC0099;">=</span> <span style="color: #008080;">8</span></pre></div></div>

<img src="http://feeds.feedburner.com/~r/webgelistirici/~4/_Xnw2zaxVmM" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.webgelistirici.com/mysql-sorgusunun-icine-aciklama-yazmak.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.webgelistirici.com/mysql-sorgusunun-icine-aciklama-yazmak.html</feedburner:origLink></item>
		<item>
		<title>CSS’de Bir Kuralı Baskın Yapmak</title>
		<link>http://feedproxy.google.com/~r/webgelistirici/~3/DUrx4FKMn5M/cssde-bir-kurali-baskin-yapmak.html</link>
		<comments>http://www.webgelistirici.com/cssde-bir-kurali-baskin-yapmak.html#comments</comments>
		<pubDate>Sun, 14 Feb 2010 07:22:19 +0000</pubDate>
		<dc:creator>Bülent Yılmaz</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[!important]]></category>
		<category><![CDATA[baskın kural]]></category>

		<guid isPermaLink="false">http://www.webgelistirici.com/?p=23</guid>
		<description><![CDATA[Makale içeriğini görmek için lütfen makale başlığına tıklayınız.]]></description>
			<content:encoded><![CDATA[<p><!-- 		@page { margin: 2cm } 		P { margin-bottom: 0.21cm } -->Bir element içinde farklı yerlerde tanımlanmış CSS kurallarının çakışması halinde hangisinin geçerli olacağını elemente yakınlık belirler. Örneğin elementin style niteliği içindeki bir CSS kuralı, sayfanın baş tarafında <code>&lt;style&gt;&lt;/style&gt;</code> bloğu içinde bulunan bir CSS kuralına göre daha baskındır. Ancak <code><strong>!important</strong></code> ifadesi ile hangi kuralın baskın olacağına biz karar verebiliriz.</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">style</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/css&quot;</span>&gt;</span>
.etiket { color: red; }
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">style</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">span</span> <span style="color: #000066;">style</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;color: green;&quot;</span>&gt;</span>merhaba<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">span</span>&gt;</span></pre></div></div>

<p>Yukarıdaki durumda &#8220;merhaba&#8221; yazısının rengi yeşil olacaktır.</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">style</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/css&quot;</span>&gt;</span>
.etiket { color: red !important; }
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">style</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">span</span> <span style="color: #000066;">style</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;color: green;&quot;</span>&gt;</span>merhaba<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">span</span>&gt;</span></pre></div></div>

<p>Yukarıdaki durumda ise yazı rengi kırmızı olacaktır. <code>!important</code> ifadesi ile çakışma durumunda hangi kuralın baskın olacağını biz belirlemiş olduk.</p>
<img src="http://feeds.feedburner.com/~r/webgelistirici/~4/DUrx4FKMn5M" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.webgelistirici.com/cssde-bir-kurali-baskin-yapmak.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.webgelistirici.com/cssde-bir-kurali-baskin-yapmak.html</feedburner:origLink></item>
		<item>
		<title>Limitli Bir Sorgunun Limitsiz Halinin Sonuç Sayısını Bulmak</title>
		<link>http://feedproxy.google.com/~r/webgelistirici/~3/QM8pGiNRWY8/limitli-bir-sorgunun-limitsiz-halinin-sonuc-sayisini-bulmak.html</link>
		<comments>http://www.webgelistirici.com/limitli-bir-sorgunun-limitsiz-halinin-sonuc-sayisini-bulmak.html#comments</comments>
		<pubDate>Sun, 14 Feb 2010 07:11:25 +0000</pubDate>
		<dc:creator>Bülent Yılmaz</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[limit]]></category>
		<category><![CDATA[SQL_CALC_FOUND_ROWS]]></category>

		<guid isPermaLink="false">http://www.webgelistirici.com/?p=17</guid>
		<description><![CDATA[Makale içeriğini görmek için lütfen makale başlığına tıklayınız.]]></description>
			<content:encoded><![CDATA[<p><!-- 		@page { margin: 2cm } 		P { margin-bottom: 0.21cm } -->SQL&#8217;de bir sorgunun döndüreceği sonuç sayısı <code>limit</code> eki ile sınırlandırılır. Özellikle sayfalama yaparken bunu çok sık kullanırız. Örneğin</p>

<div class="wp_syntax"><div class="code"><pre class="mysql" style="font-family:monospace;"><span style="color: #990099; font-weight: bold;">SELECT</span> <span style="color: #CC0099;">*</span> <span style="color: #990099; font-weight: bold;">FROM</span> tablo <span style="color: #990099; font-weight: bold;">WHERE</span> id <span style="color: #CC0099;">&gt;</span> <span style="color: #008080;">100</span> <span style="color: #990099; font-weight: bold;">LIMIT</span> <span style="color: #008080;">10</span></pre></div></div>

<p>sorgusu bize şarta uyan ilk 10 kaydı getirecektir. Peki ama limit koymasaydık toplam kaç kayıt gelecekti? Toplam kayıt sayısını bulmak için aklımıza gelen ilk yol aynı sorguyu limitsiz olarak ikinci sefer işletmektir. Bunun yerine MySQL&#8217;in <code><strong>SQL_CALC_FOUND_ROWS</strong></code> ifadesi böyle bir durumda bizi ikinci bir sorgu işletmekten kurtarıyor.</p>

<div class="wp_syntax"><div class="code"><pre class="mysql" style="font-family:monospace;"><span style="color: #990099; font-weight: bold;">SELECT</span> <span style="color: #990099; font-weight: bold;">SQL_CALC_FOUND_ROWS</span> <span style="color: #CC0099;">*</span> <span style="color: #990099; font-weight: bold;">FROM</span> tablo <span style="color: #990099; font-weight: bold;">WHERE</span> id <span style="color: #CC0099;">&gt;</span> <span style="color: #008080;">100</span> <span style="color: #990099; font-weight: bold;">LIMIT</span> <span style="color: #008080;">10</span></pre></div></div>

<p>Yukarıdaki sorgunun limitsiz halinin sonuç sayısını bulmak için aşağıdaki yöntemi kullanıyoruz.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$toplam_kayit_sayisi_s</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot; SELECT FOUND_ROWS() AS adet &quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$toplam_kayit_sayisi_fa</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_fetch_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$toplam_kayit_sayisi_s</span><span style="color: #339933;">,</span> MYSQL_ASSOC<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$toplam_kayit_sayisi</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$toplam_kayit_sayisi_fa</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'adet'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Böylece yeni bir sorgu işletmeden toplam kayıt sayısını elde etmiş oluruz. Yukarıdaki işlemler, kendisinden önce <code>SQL_CALC_FOUND_ROWS</code> ifadesi geçen en sonuncu sorgu için uygulanacaktır.</p>
<img src="http://feeds.feedburner.com/~r/webgelistirici/~4/QM8pGiNRWY8" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.webgelistirici.com/limitli-bir-sorgunun-limitsiz-halinin-sonuc-sayisini-bulmak.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.webgelistirici.com/limitli-bir-sorgunun-limitsiz-halinin-sonuc-sayisini-bulmak.html</feedburner:origLink></item>
		<item>
		<title>Temel XHTML kuralları</title>
		<link>http://feedproxy.google.com/~r/webgelistirici/~3/dzJb3ahAJLM/temel-xhtml-kurallari.html</link>
		<comments>http://www.webgelistirici.com/temel-xhtml-kurallari.html#comments</comments>
		<pubDate>Sun, 14 Feb 2010 06:51:03 +0000</pubDate>
		<dc:creator>Bülent Yılmaz</dc:creator>
				<category><![CDATA[HTML / XHTML]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[XML]]></category>

		<guid isPermaLink="false">http://www.webgelistirici.com/?p=12</guid>
		<description><![CDATA[Makale içeriğini görmek için lütfen makale başlığına tıklayınız.]]></description>
			<content:encoded><![CDATA[<p><!-- 		@page { margin: 2cm } 		P { margin-bottom: 0.21cm } --></p>
<ol>
<li>Tüm element ve nitelikler küçük harfle yazılmalıdır.</li>
<li>Elementlerin içiçe geçme sırasına dikkat edilmelidir. Açılan imler sırasıyla 	kapatılmalıdır. Örneğin <code>&lt;b&gt;&lt;i&gt;merhaba&lt;/b&gt;&lt;/i&gt;</code> şeklinde kullanım yanlıştır, doğrusu <code>&lt;b&gt;&lt;i&gt;merhaba&lt;/i&gt;&lt;/b&gt;</code> şeklindedir.</li>
<li>Bitiş imi olan elementlerde bitiş imi mutlaka 	kullanılmalıdır. Örneğin <code>&lt;p&gt;</code> imi daima <code>&lt;/p&gt;</code> imi ile bitmelidir.</li>
<li>İçeriği olmayan elementlerin sonuna &#8220;/&#8221; konmalıdır. <code>&lt;br/&gt;, 	&lt;hr/&gt; </code>gibi</li>
<li>Nitelikler mutlaka değer 	verilerek kullanılmalıdr. Örneğin <code>&lt;input type="checkbox" 	checked /&gt;</code> şeklinde kullanım yanlıştır, doğrusu <code>&lt;input 	type="checkbox" checked="checked" /&gt; </code>şeklindedir.</li>
<li><code>&lt;a&gt;</code> elementinde <code>title</code> niteliğinin, <code>&lt;img/&gt;</code> elementinde ise <code>alt</code> niteliğinin 	kullanımına özen gösterilmelidir.</li>
<li>Dökümanın DTD (Document Type Definition) tanımına uygun sözdizimi 	kullanılmalıdır.</li>
</ol>
<img src="http://feeds.feedburner.com/~r/webgelistirici/~4/dzJb3ahAJLM" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.webgelistirici.com/temel-xhtml-kurallari.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.webgelistirici.com/temel-xhtml-kurallari.html</feedburner:origLink></item>
		<item>
		<title>Luhn Algoritması ile Kredi Kartı Numarası Doğrulama</title>
		<link>http://feedproxy.google.com/~r/webgelistirici/~3/ichIUp10z1M/luhn-algoritmasi-ile-kredi-karti-dogrulamasi.html</link>
		<comments>http://www.webgelistirici.com/luhn-algoritmasi-ile-kredi-karti-dogrulamasi.html#comments</comments>
		<pubDate>Sun, 14 Feb 2010 06:40:37 +0000</pubDate>
		<dc:creator>Bülent Yılmaz</dc:creator>
				<category><![CDATA[Diğer]]></category>
		<category><![CDATA[kredi karti numarası doğrulama]]></category>
		<category><![CDATA[Luhn algoritması]]></category>

		<guid isPermaLink="false">http://www.webgelistirici.com/?p=9</guid>
		<description><![CDATA[Makale içeriğini görmek için lütfen makale başlığına tıklayınız.]]></description>
			<content:encoded><![CDATA[<p>Kredi kartı numarası doğrulamada kullanılan Luhn algoritmasının çalışma prensibi şöyledir:</p>
<p>Örneğin hayali <code>7419 8339 5689 1008</code> numarasını ele alalım.</p>
<p><span style="text-decoration: underline;">1. adım:</span><br />
Tek hanelerdeki rakamlar toplanır.<br />
4, 9, 3, 9, 6, 9, 0, 8 rakamları için;<br />
<code>4 + 9 + 3 + 9 + 6 + 9 + 0 + 8 = <strong>48</strong></code></p>
<p><span style="text-decoration: underline;">2. adım:</span><br />
Çift hanelerdeki rakamlar 2 ile çarpılır ve elde edilen sayıların basamakları toplanır.<br />
7, 1, 8, 3, 5, 8, 1, 0 rakamlarını 2 ile çarparsak sırasıyla 14, 2, 16, 6, 10, 16, 2, 0 sayılarını elde ederiz.<br />
Elde ettiğimiz sayıların basamaklarındaki rakamları toplarsak;<br />
<code>5 + 2 + 7 + 6 + 1 + 7 + 2 + 0 = <strong>30</strong></code></p>
<p><span style="text-decoration: underline;">3. adım:</span><br />
Hesaplanan iki toplam sonucu birbirleriyle toplanır. Elde edilen sayı 10&#8242;un katı ise bu kredi kartı numarası geçerli bir numaradır.<br />
<code>48 + 30 = <strong>78</strong></code> (10&#8242;un katı olmadığı için numara geçersizdir!)</p>
<img src="http://feeds.feedburner.com/~r/webgelistirici/~4/ichIUp10z1M" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.webgelistirici.com/luhn-algoritmasi-ile-kredi-karti-dogrulamasi.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.webgelistirici.com/luhn-algoritmasi-ile-kredi-karti-dogrulamasi.html</feedburner:origLink></item>
	</channel>
</rss>

