Weakref::acquire> <Tipos Resource
Last updated: Fri, 24 Feb 2012

The Weakref class

(No version information available, might only be in SVN)

Introdução

The Weakref class provides a gateway to objects without preventing the garbage collector from freeing those objects. It also provides a way to turn a weak reference into a strong one.

Sinopse da classe

Weakref {
/* Métodos */
public __construct ([ object $object ] )
public bool acquire ( void )
public object get ( void )
public bool release ( void )
public bool valid ( void )
}

Exemplos

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

O exemplo acima irá imprimir:

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

Índice



User Contributed Notes
Weakref
There are no user contributed notes for this page.

Weakref::acquire> <Tipos Resource
Last updated: Fri, 24 Feb 2012