Yorum Yok ↓
Sınıfınızı aynı sayfada birden fazla kullanmanız gerebiliyor. Böyle durumlarda sınıfı 2. kez başlatmak yerine clone yaparak kullanabilirsiniz. Böylelikle bellekte ekstra olarak yer kaplamaz.
<pre><?php
class bilgigoster
{
private $ad;
private $site;
public function ad($ad)
{
$this->ad = $ad;
return $this;
}
public function site($site)
{
$this->site = $site;
return $this;
}
public function getir()
{
echo $this->ad.' sitesi: '.$this->site;
}
public function __clone() {}
}
$site = new bilgigoster;
$site->ad('Nurettin')->site("www.tasarimrehberi.com")->getir();
echo "<hr>";
$site2 = $site;
$site2->getir();
echo "<hr>";
$site3 = clone $site;
$site3->getir();
?></pre>
Kaynak:
Php OOP : Prototype Design Pattern
