Draft for weakref documentation

git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@315918 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
Etienne Kneuss 2011-08-31 19:47:32 +00:00
parent 7a8db50730
commit 9f0a565c3d
10 changed files with 810 additions and 0 deletions

View file

@ -213,6 +213,7 @@
<listitem><simpara><xref linkend="book.vpopmail"/></simpara></listitem>
<listitem><simpara><xref linkend="book.w32api"/></simpara></listitem>
<listitem><simpara><xref linkend="book.wddx"/></simpara></listitem>
<listitem><simpara><xref linkend="book.weakref"/></simpara></listitem>
<listitem><simpara><xref linkend="book.win32ps"/></simpara></listitem>
<listitem><simpara><xref linkend="book.win32service"/></simpara></listitem>
<listitem><simpara><xref linkend="book.wincache"/></simpara></listitem>
@ -561,6 +562,7 @@
<listitem><para><xref linkend="book.tcpwrap"/></para></listitem>
<listitem><para><xref linkend="book.vpopmail"/></para></listitem>
<listitem><para><xref linkend="book.w32api"/></para></listitem>
<listitem><para><xref linkend="book.weakref"/></para></listitem>
<listitem><para><xref linkend="book.win32ps"/></para></listitem>
<listitem><para><xref linkend="book.win32service"/></para></listitem>
<listitem><para><xref linkend="book.wincache"/></para></listitem>

View file

@ -0,0 +1,92 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision: $ -->
<!-- Membership: pecl -->
<book xml:id="book.weakref" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
<title>Weak References</title>
<titleabbrev>Weakref</titleabbrev>
<preface xml:id="intro.weakref">
&reftitle.intro;
<para>
Weak references provide a non-intrusive gateway to ephemere objects. Unlike
normal (strong) references, weak references do not prevent the garbage
collector from freeing that object. For this reason, an object may be
destroyed even though a weak reference to that object still exists. In such
conditions, the weak reference seamlessly becomes invalid.
</para>
<para>
<example>
<title><classname>Weakref</classname> usage example</title>
<programlisting role="php">
<![CDATA[
<?php
class MyClass {
public function __destruct() {
echo "Destroying object!\n";
}
}
$o1 = new MyClass;
$r1 = new Weakref($o1);
if ($r1->valid()) {
echo "Object still exists!\n";
var_dump($r1->get());
} else {
echo "Object is dead!\n";
}
unset($o1);
if ($r1->valid()) {
echo "Object still exists!\n";
var_dump($r1->get());
} else {
echo "Object is dead!\n";
}
?>
]]>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
Object still exists!
object(MyClass)#1 (0) {
}
Destroying object!
Object is dead!
]]>
</screen>
</example>
</para>
</preface>
&reference.weakref.setup;
&reference.weakref.weakref;
</book>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->

View file

@ -0,0 +1,53 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision: $ -->
<chapter xml:id="weakref.setup" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
&reftitle.setup;
<section xml:id="weakref.requirements">
&reftitle.required;
&no.requirement;
</section>
<section xml:id="weakref.installation">
&reftitle.install;
<para>
&pecl.moved;
</para>
<para>
&pecl.info;
<link xlink:href="&url.pecl.package;weakref">&url.pecl.package;weakref</link>.
</para>
<para>
&pecl.windows.download;
</para>
</section>
<section xml:id="weakref.resources">
&reftitle.resources;
&no.resource;
</section>
</chapter>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->

View file

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision: $ -->
<phpdoc:classref xmlns:phpdoc="http://php.net/ns/phpdoc" xml:id="class.weakref" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude">
<title>The Weakref class</title>
<titleabbrev>Weakref</titleabbrev>
<partintro>
<!-- {{{ weakref intro -->
<section xml:id="weakref.intro">
&reftitle.intro;
<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.
</para>
</section>
<!-- }}} -->
<section xml:id="weakref.synopsis">
&reftitle.classsynopsis;
<!-- {{{ Synopsis -->
<classsynopsis>
<ooclass><classname>Weakref</classname></ooclass>
<!-- {{{ Class synopsis -->
<classsynopsisinfo>
<ooclass>
<classname>Weakref</classname>
</ooclass>
</classsynopsisinfo>
<!-- }}} -->
<classsynopsisinfo role="comment">&Methods;</classsynopsisinfo>
<xi:include xpointer="xmlns(db=http://docbook.org/ns/docbook) xpointer(id('class.weakref')/db:refentry/db:refsect1[@role='description']/descendant::db:constructorsynopsis[1])" />
<xi:include xpointer="xmlns(db=http://docbook.org/ns/docbook) xpointer(id('class.weakref')/db:refentry/db:refsect1[@role='description']/descendant::db:methodsynopsis[1])" />
</classsynopsis>
</section>
<!-- {{{ weakref examples -->
<section xml:id="weakref.examples">
&reftitle.examples;
<para>
<example>
<title><classname>Weakref</classname> usage example</title>
<programlisting role="php">
<![CDATA[
<?php
class MyClass {
public function __destruct() {
echo "Destroying object!\n";
}
}
$o1 = new MyClass;
$r1 = new Weakref($o1);
if ($r1->valid()) {
echo "Object still exists!\n";
var_dump($r1->get());
} else {
echo "Object is dead!\n";
}
unset($o1);
if ($r1->valid()) {
echo "Object still exists!\n";
var_dump($r1->get());
} else {
echo "Object is dead!\n";
}
?>
]]>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
Object still exists!
object(MyClass)#1 (0) {
}
Destroying object!
Object is dead!
]]>
</screen>
</example>
</para>
</section>
<!-- }}} -->
</partintro>
&reference.weakref.entities.weakref;
</phpdoc:classref>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->

View file

@ -0,0 +1,164 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- $Revision: $ -->
<refentry xml:id="weakref.acquire" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>Weakref::acquire</refname>
<refpurpose>Aquires a strong reference on that object</refpurpose>
</refnamediv>
<refsect1 role="description">
&reftitle.description;
<methodsynopsis>
<modifier>public</modifier> <type>bool</type><methodname>Weakref::acquire</methodname>
<void/>
</methodsynopsis>
<para>
Acquires a strong reference on that object, virtually turning the weak
reference into a strong one.
</para>
</refsect1>
<refsect1 role="parameters">
&reftitle.parameters;
&no.function.parameters;
</refsect1>
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
Returns &true; if the reference was valid and could be turned into a strong
reference, &false; otherwise.
</para>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<para>
<example>
<title><function>Weakref::acquire</function> example</title>
<programlisting role="php">
<![CDATA[
<?php
class MyClass {
public function __destruct() {
echo "Destroying object!\n";
}
}
$o1 = new MyClass;
$r1 = new Weakref($o1);
$r1->acquire();
echo "Unsetting o1...\n";
unset($o1);
$o2 = $r1->get();
$r1->release();
echo "Unsetting o2...\n";
unset($o2);
?>
]]>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
Unsetting o1...
Unsetting o2...
Destroying object!
]]>
</screen>
</example>
</para>
<para>
<example>
<title>Nested acquire/release example</title>
<programlisting role="php">
<![CDATA[
<?php
class MyClass {
public function __destruct() {
echo "Destroying object!\n";
}
}
$o1 = new MyClass;
$r1 = new Weakref($o1);
echo "Acquiring...\n";
$r1->acquire();
echo " Unsetting...\n";
unset($o1);
echo " Acquiring...\n";
$r1->acquire();
echo " Acquiring...\n";
$r1->acquire();
echo " Releasing...\n";
$r1->release();
echo " Releasing...\n";
$r1->release();
echo "Releasing...\n";
$r1->release();
?>
]]>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
Acquiring...
Unsetting...
Acquiring...
Acquiring...
Releasing...
Releasing...
Releasing...
Destroying object!
]]>
</screen>
</example>
</para>
</refsect1>
<refsect1 role="seealso">
&reftitle.seealso;
<para>
<simplelist>
<member><methodname>Weakref::release</methodname></member>
</simplelist>
</para>
</refsect1>
</refentry>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->

View file

@ -0,0 +1,113 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- $Revision: $ -->
<refentry xml:id="weakref.construct" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>Weakref::__construct</refname>
<refpurpose>Constructs a new weak reference</refpurpose>
</refnamediv>
<refsect1 role="description">
&reftitle.description;
<constructorsynopsis>
<modifier>public</modifier> <methodname>Weakref::__construct</methodname>
<methodparam choice="opt"><type>object</type><parameter>object</parameter></methodparam>
</constructorsynopsis>
<para>
Constructs a new weak reference.
</para>
</refsect1>
<refsect1 role="parameters">
&reftitle.parameters;
<para>
<variablelist>
<varlistentry>
<term><parameter>object</parameter></term>
<listitem>
<para>
The object to reference.
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
</refsect1>
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
&return.void;
</para>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<para>
<example>
<title><function>Weakref::__construct</function> example</title>
<programlisting role="php">
<![CDATA[
<?php
class MyClass {
public function __destruct() {
echo "Destroying object!\n";
}
}
$o1 = new MyClass;
$r1 = new Weakref($o1);
if ($r1->valid()) {
echo "Object still exists!\n";
var_dump($r1->get());
} else {
echo "Object is dead!\n";
}
unset($o1);
if ($r1->valid()) {
echo "Object still exists!\n";
var_dump($r1->get());
} else {
echo "Object is dead!\n";
}
?>
]]>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
Object still exists!
object(MyClass)#1 (0) {
}
Destroying object!
Object is dead!
]]>
</screen>
</example>
</para>
</refsect1>
</refentry>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->

View file

@ -0,0 +1,62 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- $Revision: $ -->
<refentry xml:id="weakref.get" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>Weakref::get</refname>
<refpurpose>Returns the object pointed to by the weak reference</refpurpose>
</refnamediv>
<refsect1 role="description">
&reftitle.description;
<methodsynopsis>
<modifier>public</modifier> <type>object</type><methodname>Weakref::get</methodname>
<void/>
</methodsynopsis>
<para>
Returns the object pointed to by the weak reference.
</para>
</refsect1>
<refsect1 role="parameters">
&reftitle.parameters;
&no.function.parameters;
</refsect1>
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
Returns the object if the reference is still valid, &null; otherwise.
</para>
</refsect1>
<refsect1 role="seealso">
&reftitle.seealso;
<para>
<simplelist>
<member><methodname>Weakref::valid</methodname></member>
</simplelist>
</para>
</refsect1>
</refentry>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->

View file

@ -0,0 +1,108 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- $Revision: $ -->
<refentry xml:id="weakref.release" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>Weakref::release</refname>
<refpurpose>Releases a previously acquired reference</refpurpose>
</refnamediv>
<refsect1 role="description">
&reftitle.description;
<methodsynopsis>
<modifier>public</modifier> <type>bool</type><methodname>Weakref::release</methodname>
<void/>
</methodsynopsis>
<para>
Releases a previously acquired reference. Potentially turning a strong
reference back into a weak reference.
</para>
</refsect1>
<refsect1 role="parameters">
&reftitle.parameters;
&no.function.parameters;
</refsect1>
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
Returns &true; if the reference was previously acquired and thus could be
released, &false; otherwise.
</para>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<para>
<example>
<title><function>Weakref::release</function> example</title>
<programlisting role="php">
<![CDATA[
<?php
class MyClass {
public function __destruct() {
echo "Destroying object!\n";
}
}
$o1 = new MyClass;
$r1 = new Weakref($o1);
$r1->acquire();
echo "Unsetting o1...\n";
unset($o1);
$o2 = $r1->get();
$r1->release();
echo "Unsetting o2...\n";
unset($o2);
?>
]]>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
Unsetting o1...
Unsetting o2...
Destroying object!
]]>
</screen>
</example>
</para>
</refsect1>
<refsect1 role="seealso">
&reftitle.seealso;
<para>
<simplelist>
<member><methodname>Weakref::acquire</methodname></member>
</simplelist>
</para>
</refsect1>
</refentry>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->

View file

@ -0,0 +1,33 @@
<?php
class MyClass {
public function __destruct() {
echo "Destroying object!\n";
}
}
$o1 = new MyClass;
$r1 = new Weakref($o1);
echo "Acquiring...\n";
$r1->acquire();
echo " Unsetting...\n";
unset($o1);
echo " Acquiring...\n";
$r1->acquire();
echo " Acquiring...\n";
$r1->acquire();
echo " Releasing...\n";
$r1->release();
echo " Releasing...\n";
$r1->release();
echo "Releasing...\n";
$r1->release();
?>

View file

@ -0,0 +1,63 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- $Revision: $ -->
<refentry xml:id="weakref.valid" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>Weakref::valid</refname>
<refpurpose>Checks whether the object referenced still exists</refpurpose>
</refnamediv>
<refsect1 role="description">
&reftitle.description;
<methodsynopsis>
<modifier>public</modifier> <type>bool</type><methodname>Weakref::valid</methodname>
<void/>
</methodsynopsis>
<para>
Checks whether the object referenced still exists.
</para>
</refsect1>
<refsect1 role="parameters">
&reftitle.parameters;
&no.function.parameters;
</refsect1>
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
Returns &true; if the object still exists and is thus still accessible via
<methodname>Weakref::get</methodname>, &false; otherwise.
</para>
</refsect1>
<refsect1 role="seealso">
&reftitle.seealso;
<para>
<simplelist>
<member><methodname>Weakref::get</methodname></member>
</simplelist>
</para>
</refsect1>
</refentry>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->