首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

WeakMap (class)

Introduction

(PECL weakref >= 0.2.0)

Class synopsis

WeakMap implements Countable , ArrayAccess , Iterator {

/* Methods */

代码语言:javascript
复制
public __construct ( void )
代码语言:javascript
复制
public int count ( void )
代码语言:javascript
复制
public mixed current ( void )
代码语言:javascript
复制
public object key ( void )
代码语言:javascript
复制
public void next ( void )
代码语言:javascript
复制
public bool offsetExists ( object $object )
代码语言:javascript
复制
public mixed offsetGet ( object $object )
代码语言:javascript
复制
public void offsetSet ( object $object , mixed $value )
代码语言:javascript
复制
public void offsetUnset ( object $object )
代码语言:javascript
复制
public void rewind ( void )
代码语言:javascript
复制
public bool valid ( void )

}

Examples

Example #1 Weakmap usage example

代码语言:javascript
复制
<?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:

代码语言:javascript
复制
int(1)
Unsetting..
Dead!
Done
int(0)

Table of Contents

  • WeakMap::__construct — Constructs a new map
  • WeakMap::count — Counts the number of live entries in the map
  • WeakMap::current — Returns the current value under iteration
  • WeakMap::key — Returns the current key under iteration.
  • WeakMap::offsetExists — Checks whether a certain object is in the map
  • WeakMap::offsetGet — Returns the value pointed to by a certain object
  • WeakMap::offsetSet — Updates the map with a new key-value pair
  • WeakMap::offsetUnset — Removes an entry from the map
  • WeakMap::rewind — Rewinds the iterator to the beginning of the map
  • WeakMap::valid — Returns whether the iterator is still on a valid map element

← Weakref::valid

WeakMap::__construct →

代码语言:txt
复制
 ? 1997–2017 The PHP Documentation Group

Licensed under the Creative Commons Attribution License v3.0 or later.

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com