PHP-Logo
Druckansicht von http://www.php-homepage.de/manual/intro.weakref.php

PHP-Logo
[ Main Menue ]
Homepage
Downloads
Artikel
Scripts
Forum
PHP-Manual
Links
News
Freelancer
Bücher
RuDolF
Suche
Misc
Über diese Seite
Kontakt
Wunschzettel
MyGuestbook
*
[ Suche ]
*
[ Manual ]
*

Follow on Twitter - @phphomepage

RSS Feed blogoscoop
 Weakref  Letztes Update:
18.05.2012
Installation/Konfiguration 

Einführung

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.

Beispiel #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";
}
?>

Das oben gezeigte Beispiel erzeugt folgende Ausgabe:

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

© Copyright 1999 - 2011 by Mark Kronsbein | Impressum | NutzungsbedingungenWeiterempfehlen | Seitenanfang
0.0248