downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

설치/설정> <Weakref
[edit] Last updated: Sat, 07 Jan 2012

view this page in

소개

Weak references provide a non-intrusive gateway to ephemeral objects. Unlike normal (strong) references, weak references do not prevent the garbage collector from freeing that object. For this reason, an object may be destroyed even though a weak reference to that object still exists. In such conditions, the weak reference seamlessly becomes invalid.

Example #1 Weakref usage example

<?php
class MyClass {
    public function 
__destruct() {
        echo 
"Destroying object!\n";
    }
}

$o1 = new MyClass;

$r1 = new Weakref($o1);

if (
$r1->valid()) {
    echo 
"Object still exists!\n";
    
var_dump($r1->get());
} else {
    echo 
"Object is dead!\n";
}

unset(
$o1);

if (
$r1->valid()) {
    echo 
"Object still exists!\n";
    
var_dump($r1->get());
} else {
    echo 
"Object is dead!\n";
}
?>

위 예제의 출력:

Object still exists!
object(MyClass)#1 (0) {
}
Destroying object!
Object is dead!



add a note add a note User Contributed Notes 소개
There are no user contributed notes for this page.

 
show source | credits | sitemap | contact | advertising | mirror sites