20.01.2015 Views

PHP 5 & MySQLi

PHP 5 & MySQLi

PHP 5 & MySQLi

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Destructors<br />

destructor จะถูกเรียกเมื1อต้องการทําลายอ็อบเจ็ค ในโปรแกรมบางภาษา คุณต้องกําจัดอ็อบเจ็คที1คุณสร้างด้วย<br />

ตัวเอง แต่ใน <strong>PHP</strong> มันจะจัดการโดย Garbage Collector ซึ1งจะช่วยในการทําลายอ็อบเจ็คอัตโนมัติ เมื1อไม่จําเป็นดัง<br />

ตัวอย่างต่อไปนีซึ1งเป็นการขยายตัวอย่างก่อนหน้านี:<br />

name = $name;<br />

}<br />

}<br />

public function __destruct()<br />

{<br />

}<br />

echo "I'm dead now :(";<br />

$animal = new Animal("Bob");<br />

echo "Name of the animal: " . $animal->name;<br />

><br />

ที1คุณเห็น destructor ก็เหมือน constructor เฉพาะชื1อที1แตกต่างกัน ถ้าคุณลองใช้ตัวอย่างนีคุณจะเห็นข้อความ<br />

constructor แรก แล้วชื1อของสัตว์ที1เราส่งออกด้วยตนเองในบรรทัดสุดท้าย และหลังจากที1สคริปต์สินสุดอ็อบเจ็คถูก<br />

ทําลาย destructor ถูกเรียกข้อความเกี1ยวกับสัตว์ก็จะไม่แสดงผลออกมา

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!