[DOC-CVS] [doc-en] master: (void) casting: Add syntax for PHP 8.5 (#5546)

[email protected] (Jordi Kroon via GitHub) Fri, 8 May 2026 11:36:52 +0000
Newsgroups php.doc.cvs
Message-ID <[email protected]>
Author: Jordi Kroon (jordikroon)
Committer: GitHub (web-flow)
Pusher: jordikroon
Date: 2026-05-08T13:36:50+02:00

Commit: https://github.com/php/doc-en/commit/50f76f26914c5a9e61aa26f2e36c4acb362a48fd
Raw diff: https://github.com/php/doc-en/commit/50f76f26914c5a9e61aa26f2e36c4acb362a48fd.diff

(void) casting: Add syntax for PHP 8.5 (#5546)

* Add (void) casting syntax for PHP 8.5

Changed paths:
  M  language/types/type-juggling.xml
  M  language/types/void.xml


Diff:

diff --git a/language/types/type-juggling.xml b/language/types/type-juggling.xml
index d3f177f9b1cc..6c4efcb7aa15 100644
--- a/language/types/type-juggling.xml
+++ b/language/types/type-juggling.xml
@@ -317,6 +317,12 @@ var_dump($bar);
    <member><literal>(unset)</literal> - cast to <type>NULL</type></member>
   </simplelist>
 
+  <simpara>
+   The <link linkend="language.types.void.casting"><literal>(void)</literal></link>
+   cast is also available as of PHP 8.5.0, but it is not a value conversion.
+   It is used as a statement to explicitly discard the result of an expression.
+  </simpara>
+
   <warning>
    <para>
     <literal>(integer)</literal> is an alias of the <literal>(int)</literal> cast.
@@ -422,6 +428,7 @@ if ($fst === $str) {
     <member><link linkend="language.types.object.casting">Converting to object</link></member>
     <member><link linkend="language.types.resource.casting">Converting to resource</link></member>
     <member><link linkend="language.types.null.casting">Converting to NULL</link></member>
+    <member><link linkend="language.types.void.casting">Discarding a value with <literal>(void)</literal></link></member>
     <member><link linkend="types.comparisons">The type comparison tables</link></member>
    </simplelist>
   </para>
diff --git a/language/types/void.xml b/language/types/void.xml
index 9b8e3af05fe7..5f3bd1025955 100644
--- a/language/types/void.xml
+++ b/language/types/void.xml
@@ -17,6 +17,39 @@
   </simpara>
  </note>
 
+ <sect2 xml:id="language.types.void.casting">
+  <title>Discarding a value with <literal>(void)</literal></title>
+
+  <simpara>
+   The <literal>(void)</literal> syntax may be used to explicitly discard the
+   result of an expression. This is useful to indicate that ignoring a return
+   value is intentional, especially when calling a function or method marked
+   with the <classname>NoDiscard</classname>
+   attribute.
+  </simpara>
+
+  <simpara>
+   Unlike other casts, <literal>(void)</literal> does not convert the value to
+   another type and does not produce a value. It is a statement and cannot be
+   used as part of an expression.
+  </simpara>
+
+  <example>
+   <title>Discarding a return value</title>
+   <programlisting role="php" annotations="non-interactive">
+    <![CDATA[
+<?php
+#[\NoDiscard]
+function process(): bool {
+    return true;
+}
+
+(void) process(); // Explicitly discard the return value
+?>
+]]>
+   </programlisting>
+  </example>
+ </sect2>
 </sect1>
 <!-- Keep this comment at the end of the file
 Local variables: