(PECL weakref >= 0.2.0)
Examples:
Weakmap usage example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | <?php $wm = new WeakMap(); $o = new StdClass; class A { public function __destruct() { echo "Dead!\n" ; } } $wm [ $o ] = new A; var_dump( count ( $wm )); echo "Unsetting..\n" ; unset( $o ); echo "Done\n" ; var_dump( count ( $wm )); |
The above example will output:
int(1) Unsetting.. Dead! Done int(0)