La classe WeakMap

(PECL weakref >= 0.2.0)

Introduction

Synopsis de la classe

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

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