Sophie

Sophie

distrib > Mageia > 4 > x86_64 > by-pkgid > f800694edefe91adea2624f711a41a2d > files > 1099

php-manual-en-5.5.7-1.mga4.noarch.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>The WeakRef class</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="weakref.resources.html">Resource Types</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="weakref.acquire.html">Weakref::acquire</a></div>
 <div class="up"><a href="book.weakref.html">Weakref</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="class.weakref" class="reference">
 <h1 class="title">The WeakRef class</h1>
 

 <div class="partintro"><p class="verinfo">(PECL weakref &gt;= 0.1.0)</p>


  <div class="section" id="weakref.intro">
   <h2 class="title">Introduction</h2>
   <p class="para">
    The WeakRef class provides a gateway to objects without preventing the garbage collector from freeing those objects.
    It also provides a way to turn a weak reference into a strong one.
   </p>
  </div>


  <div class="section" id="weakref.synopsis">
   <h2 class="title">Class synopsis</h2>


   <div class="classsynopsis">
    <div class="ooclass"></div>



    <div class="classsynopsisinfo">
     <span class="ooclass">
      <strong class="classname">WeakRef</strong>
     </span>

     {</div>


    <div class="classsynopsisinfo classsynopsisinfo_comment">/* Methods */</div>
    <div class="constructorsynopsis dc-description">
   <span class="modifier">public</span>  <span class="methodname"><a href="weakref.construct.html" class="methodname">Weakref::__construct</a></span>
    ([ <span class="methodparam"><span class="type">object</span> <code class="parameter">$object</code></span>
  ] )</div>

    <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="type">bool</span> <span class="methodname"><a href="weakref.acquire.html" class="methodname">Weakref::acquire</a></span>
    ( <span class="methodparam">void</span>
   )</div>
<div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="type">object</span> <span class="methodname"><a href="weakref.get.html" class="methodname">Weakref::get</a></span>
    ( <span class="methodparam">void</span>
   )</div>
<div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="type">bool</span> <span class="methodname"><a href="weakref.release.html" class="methodname">Weakref::release</a></span>
    ( <span class="methodparam">void</span>
   )</div>
<div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="type">bool</span> <span class="methodname"><a href="weakref.valid.html" class="methodname">Weakref::valid</a></span>
    ( <span class="methodparam">void</span>
   )</div>

   }</div>

  </div>

  <div class="section" id="weakref.examples">
   <h2 class="title">Examples</h2>
   <p class="para">
    <div class="example" id="example-548">
     <p><strong>Example #1 <strong class="classname">WeakRef</strong> usage example</strong></p>
     <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">class&nbsp;</span><span style="color: #0000BB">MyClass&nbsp;</span><span style="color: #007700">{<br />&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;function&nbsp;</span><span style="color: #0000BB">__destruct</span><span style="color: #007700">()&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"Destroying&nbsp;object!\n"</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />}<br /><br /></span><span style="color: #0000BB">$o1&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">MyClass</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">$r1&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">WeakRef</span><span style="color: #007700">(</span><span style="color: #0000BB">$o1</span><span style="color: #007700">);<br /><br />if&nbsp;(</span><span style="color: #0000BB">$r1</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">valid</span><span style="color: #007700">())&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"Object&nbsp;still&nbsp;exists!\n"</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$r1</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">get</span><span style="color: #007700">());<br />}&nbsp;else&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"Object&nbsp;is&nbsp;dead!\n"</span><span style="color: #007700">;<br />}<br /><br />unset(</span><span style="color: #0000BB">$o1</span><span style="color: #007700">);<br /><br />if&nbsp;(</span><span style="color: #0000BB">$r1</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">valid</span><span style="color: #007700">())&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"Object&nbsp;still&nbsp;exists!\n"</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$r1</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">get</span><span style="color: #007700">());<br />}&nbsp;else&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"Object&nbsp;is&nbsp;dead!\n"</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
     </div>

     <div class="example-contents"><p>The above example will output:</p></div>
     <div class="example-contents screen">
<div class="cdata"><pre>
Object still exists!
object(MyClass)#1 (0) {
}
Destroying object!
Object is dead!
</pre></div>
     </div>
    </div>
   </p>
  </div>


 </div>

 































<h2>Table of Contents</h2><ul class="chunklist chunklist_reference"><li><a href="weakref.acquire.html">Weakref::acquire</a> — Acquires a strong reference on that object</li><li><a href="weakref.construct.html">Weakref::__construct</a> — Constructs a new weak reference</li><li><a href="weakref.get.html">Weakref::get</a> — Returns the object pointed to by the weak reference</li><li><a href="weakref.release.html">Weakref::release</a> — Releases a previously acquired reference</li><li><a href="weakref.valid.html">Weakref::valid</a> — Checks whether the object referenced still exists</li></ul>
</div>
<hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="weakref.resources.html">Resource Types</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="weakref.acquire.html">Weakref::acquire</a></div>
 <div class="up"><a href="book.weakref.html">Weakref</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>