Weakref
PHP Manual

La classe WeakMap

(PECL weakref >= 0.2.0)

Introduction

Synopsis de la classe

WeakMap implements Countable , ArrayAccess , Iterator , Traversable {
/* Méthodes */
public __construct ( void )
public int count ( void )
public mixed current ( void )
public object key ( void )
public void next ( void )
public bool offsetExists ( object $object )
public mixed offsetGet ( object $object )
public void offsetSet ( object $object , mixed $value )
public void offsetUnset ( object $object )
public void rewind ( void )
public bool valid ( void )
}

Exemples

Exemple #1 Exemple d'utilisation de Weakmap

<?php
$wm 
= new WeakMap();

$o = new StdClass;

class 
{
    public function 
__destruct() {
        echo 
"Mort !\n";
    }
}

$wm[$o] = new A;

var_dump(count($wm));
echo 
"Effacement..\n";
unset(
$o);
echo 
"Fait\n";
var_dump(count($wm));

L'exemple ci-dessus va afficher :

int(1)
Effacement..
Mort !
Fait
int(0)

Sommaire


Weakref
PHP Manual