©
Dokumen ini menggunakan Manual laman web PHP Cina Lepaskan
(PECL weakref >= 0.2.0)
$object
)$object
)$object
, mixed $value
)$object
)
Example #1 Weakmap usage example
<?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 ));
以上例程会输出:
int(1) Unsetting.. Dead! Done int(0)