Skip to content

Commit cd391e6

Browse files
mmalferovjimwinsGirgias
authored
Add more details about WeakReferences (#3976)
Possible follow-up is to describe weak references in more details elsewhere in the manual. Co-authored-by: Jim Winstead <[email protected]> Co-authored-by: Gina Peter Banyard <[email protected]>
1 parent f20fa04 commit cd391e6

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

language/predefined/weakreference.xml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@
1313
<para>
1414
Weak references allow the programmer to retain a reference to an object which does not prevent
1515
the object from being destroyed. They are useful for implementing cache like structures.
16+
If the original object has been destroyed, &null; will be returned
17+
when calling the <methodname>WeakReference::get</methodname> method.
18+
The original object will be destroyed when the
19+
<link linkend="features.gc.refcounting-basics">refcount</link> for it drops to zero;
20+
creating weak references does not increase the <literal>refcount</literal> of the object being referenced.
1621
</para>
1722
<para>
1823
<classname>WeakReference</classname>s cannot be serialized.
@@ -50,11 +55,16 @@
5055
<programlisting role="php">
5156
<![CDATA[
5257
<?php
53-
$obj = new stdClass;
58+
59+
$obj = new stdClass();
5460
$weakref = WeakReference::create($obj);
61+
5562
var_dump($weakref->get());
63+
5664
unset($obj);
65+
5766
var_dump($weakref->get());
67+
5868
?>
5969
]]>
6070
</programlisting>

0 commit comments

Comments
 (0)