<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/reserved.interfaces.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'it',
  ),
  'this' => 
  array (
    0 => 'class.weakmap.php',
    1 => 'WeakMap',
    2 => 'The WeakMap class',
  ),
  'up' => 
  array (
    0 => 'reserved.interfaces.php',
    1 => 'Interfacce e Classi predefinite',
  ),
  'prev' => 
  array (
    0 => 'weakreference.get.php',
    1 => 'WeakReference::get',
  ),
  'next' => 
  array (
    0 => 'weakmap.count.php',
    1 => 'WeakMap::count',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'language/predefined/weakmap.xml',
  ),
  'history' => 
  array (
  ),
  'extra_header_links' => 
  array (
    'rel' => 'alternate',
    'href' => '/manual/en/feeds/class.weakmap.atom',
    'type' => 'application/atom+xml',
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="class.weakmap" class="reference">

 <h1 class="title">The WeakMap class</h1>
 

 <div class="partintro"><p class="verinfo">(PHP 8)</p>

  
  <div class="section" id="weakmap.intro">
   <h2 class="title">Introduzione</h2>
   <p class="para">
    A <span class="classname"><strong class="classname">WeakMap</strong></span> is map (or dictionary) that accepts objects as keys.  However, unlike the
    otherwise similar <span class="classname"><a href="class.splobjectstorage.php" class="classname">SplObjectStorage</a></span>, an object in a key of <span class="classname"><strong class="classname">WeakMap</strong></span>
    does not contribute toward the object&#039;s reference count.  That is, if at any point the only remaining reference
    to an object is the key of a <span class="classname"><strong class="classname">WeakMap</strong></span>, the object will be garbage collected and removed
    from the <span class="classname"><strong class="classname">WeakMap</strong></span>.  Its primary use case is for building caches of data derived from
    an object that do not need to live longer than the object.
   </p>
   <p class="para">
    <span class="classname"><strong class="classname">WeakMap</strong></span> implements <span class="interfacename"><a href="class.arrayaccess.php" class="interfacename">ArrayAccess</a></span>,
    <span class="interfacename"><a href="class.traversable.php" class="interfacename">Traversable</a></span> (via <span class="interfacename"><a href="class.iteratoraggregate.php" class="interfacename">IteratorAggregate</a></span>),
    and <span class="interfacename"><a href="class.countable.php" class="interfacename">Countable</a></span>, so in most cases it can be used in the same fashion as an associative array.
   </p>
  </div>
  

  <div class="section" id="weakmap.synopsis">
   <h2 class="title">Sommario della classe</h2>

   
   <div class="classsynopsis"><div class="classsynopsisinfo">
    
     <span class="modifier">final</span>
     <span class="modifier">class</span> <strong class="classname"><strong class="classname">WeakMap</strong></strong>
    

    
     <span class="modifier">implements</span>
      <a href="class.arrayaccess.php" class="interfacename">ArrayAccess</a>,

     <a href="class.countable.php" class="interfacename">Countable</a>,

     <a href="class.iteratoraggregate.php" class="interfacename">IteratorAggregate</a> {</div>

    <div class="classsynopsisinfo classsynopsisinfo_comment">/* Metodi */</div>
    <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><a href="weakmap.count.php" class="methodname">count</a></span>(): <span class="type"><a href="language.types.integer.php" class="type int">int</a></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="weakmap.getiterator.php" class="methodname">getIterator</a></span>(): <span class="type"><a href="class.iterator.php" class="type Iterator">Iterator</a></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="weakmap.offsetexists.php" class="methodname">offsetExists</a></span>(<span class="methodparam"><span class="type"><a href="language.types.object.php" class="type object">object</a></span> <code class="parameter">$object</code></span>): <span class="type"><a href="language.types.boolean.php" class="type bool">bool</a></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="weakmap.offsetget.php" class="methodname">offsetGet</a></span>(<span class="methodparam"><span class="type"><a href="language.types.object.php" class="type object">object</a></span> <code class="parameter">$object</code></span>): <span class="type"><a href="language.types.mixed.php" class="type mixed">mixed</a></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="weakmap.offsetset.php" class="methodname">offsetSet</a></span>(<span class="methodparam"><span class="type"><a href="language.types.object.php" class="type object">object</a></span> <code class="parameter">$object</code></span>, <span class="methodparam"><span class="type"><a href="language.types.mixed.php" class="type mixed">mixed</a></span> <code class="parameter">$value</code></span>): <span class="type"><a href="language.types.void.php" class="type void">void</a></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="weakmap.offsetunset.php" class="methodname">offsetUnset</a></span>(<span class="methodparam"><span class="type"><a href="language.types.object.php" class="type object">object</a></span> <code class="parameter">$object</code></span>): <span class="type"><a href="language.types.void.php" class="type void">void</a></span></div>

   }</div>
   

  </div>
  
  <div class="section" id="weakmap.examples">
   <h2 class="title">Esempi</h2>
   <p class="para">
    <div class="example" id="example-1">
     <p><strong>Example #1 <span class="classname"><strong class="classname">Weakmap</strong></span> usage example</strong></p>
     <div class="example-contents">
      <div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$wm </span><span style="color: #007700">= new </span><span style="color: #0000BB">WeakMap</span><span style="color: #007700">();<br /><br /></span><span style="color: #0000BB">$o </span><span style="color: #007700">= new </span><span style="color: #0000BB">stdClass</span><span style="color: #007700">;<br /><br />class </span><span style="color: #0000BB">A </span><span style="color: #007700">{<br />    public function </span><span style="color: #0000BB">__destruct</span><span style="color: #007700">() {<br />        echo </span><span style="color: #DD0000">"Dead!\n"</span><span style="color: #007700">;<br />    }<br />}<br /><br /></span><span style="color: #0000BB">$wm</span><span style="color: #007700">[</span><span style="color: #0000BB">$o</span><span style="color: #007700">] = new </span><span style="color: #0000BB">A</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">count</span><span style="color: #007700">(</span><span style="color: #0000BB">$wm</span><span style="color: #007700">));<br />echo </span><span style="color: #DD0000">"Unsetting...\n"</span><span style="color: #007700">;<br />unset(</span><span style="color: #0000BB">$o</span><span style="color: #007700">);<br />echo </span><span style="color: #DD0000">"Done\n"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">count</span><span style="color: #007700">(</span><span style="color: #0000BB">$wm</span><span style="color: #007700">));</span></span></code></div>
     </div>

     <div class="example-contents"><p>Il precedente esempio visualizzerà:</p></div>
     <div class="example-contents screen">
      <div class="cdata"><pre>
int(1)
Unsetting...
Dead!
Done
int(0)
</pre></div>
     </div>
    </div>
   </p>
  </div>
  

 </div>

 




 




 




 




 




 





<h2>Indice dei contenuti</h2><ul class="chunklist chunklist_reference"><li><a href="weakmap.count.php">WeakMap::count</a> — Counts the number of live entries in the map</li><li><a href="weakmap.getiterator.php">WeakMap::getIterator</a> — Retrieve an external iterator</li><li><a href="weakmap.offsetexists.php">WeakMap::offsetExists</a> — Checks whether a certain object is in the map</li><li><a href="weakmap.offsetget.php">WeakMap::offsetGet</a> — Returns the value pointed to by a certain object</li><li><a href="weakmap.offsetset.php">WeakMap::offsetSet</a> — Updates the map with a new key-value pair</li><li><a href="weakmap.offsetunset.php">WeakMap::offsetUnset</a> — Removes an entry from the map</li></ul>
</div>
<?php manual_footer($setup); ?>