Skip to content

weakreference.xml Give more details about the WeakReferences #3976

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Nov 8, 2024
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion language/predefined/weakreference.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@
<para>
Weak references allow the programmer to retain a reference to an object which does not prevent
the object from being destroyed. They are useful for implementing cache like structures.
The garbage collector will destroy the original object, and a weak reference will return &null;
when calling the <methodname>WeakReference::get</methodname> method,
only if there are no variables left that store the
<link linkend="language.oop5.references">ID of the original object</link>,
more precisely, the object is destroed only when the
<link linkend="features.gc.refcounting-basics">refcount</link> for the object is reset to zero;
at the same time, creating a weak references do not increase the reference counter.
</para>
<para>
<classname>WeakReference</classname>s cannot be serialized.
Expand Down Expand Up @@ -50,11 +57,16 @@
<programlisting role="php">
<![CDATA[
<?php
$obj = new stdClass;

$obj = new stdClass();
$weakref = WeakReference::create($obj);

var_dump($weakref->get());

unset($obj);

var_dump($weakref->get());

?>
]]>
</programlisting>
Expand Down