Skip to content
Merged
Changes from all 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: 7 additions & 7 deletions language/operators/functional.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<title>Functional Operators</title>
<titleabbrev>Functional</titleabbrev>
<para>
PHP 8.5 and later supports one operator that works directly on callables. The <literal>|></literal>
PHP 8.5 and later supports one operator that works directly on callables. The <literal>|&gt;</literal>
operator, or “pipe,” accepts a single-parameter callable on the right and passes
the left-side value to it, evaluating to the callable's result. The callable
on the right may be any valid PHP callable: a <classname>Closure</classname>,
Expand All @@ -13,15 +13,15 @@
<para>
That means the following two lines are logically equivalent.
<example>
<title>Using <literal>|></literal></title>
<title>Using <literal>|&gt;</literal></title>
<programlisting role="php">
<![CDATA[
<?php
$result = "Hello World" |> strlen(...);
print $result . PHP_EOL;
echo $result, PHP_EOL;

$result = strlen("Hello World");
print $result . PHP_EOL;
echo $result, PHP_EOL;
?>
]]>
</programlisting>
Expand All @@ -38,7 +38,7 @@ print $result . PHP_EOL;
For a single call that is not especially useful. It becomes useful when multiple calls are chained together.
That is, the following two code fragments are logically equivalent:
<example>
<title>Chaining |> calls</title>
<title>Chaining |&gt; calls</title>
<programlisting role="php">
<![CDATA[
<?php
Expand All @@ -48,15 +48,15 @@ $result = "PHP Rocks"
|> (fn($x) => array_map(strtoupper(...), $x))
|> (fn($x) => array_filter($x, fn($v) => $v != 'O'))
;
print $result . PHP_EOL;
echo $result, PHP_EOL;

$temp = "PHP Rocks";
$temp = htmlentities($temp);
$temp = str_split($temp);
$temp = array_map(strtoupper(...), $temp);
$temp = array_filter($temp, fn($v) => $v != 'O');
$result = $temp;
print $result . PHP_EOL;
echo $result, PHP_EOL;
?>
]]>
</programlisting>
Expand Down