33 <title >Functional Operators</title >
44 <titleabbrev >Functional</titleabbrev >
55 <para >
6- PHP 8.5 and later supports one operator that works directly on callables. The <literal >|> </literal >
6+ PHP 8.5 and later supports one operator that works directly on callables. The <literal >|> </literal >
77 operator, or “pipe,” accepts a single-parameter callable on the right and passes
88 the left-side value to it, evaluating to the callable's result. The callable
99 on the right may be any valid PHP callable: a <classname >Closure</classname >,
1313 <para >
1414 That means the following two lines are logically equivalent.
1515 <example >
16- <title >Using <literal >|> </literal ></title >
16+ <title >Using <literal >|> </literal ></title >
1717 <programlisting role =" php" >
1818<![CDATA[
1919<?php
2020$result = "Hello World" |> strlen(...);
21- print $result . PHP_EOL;
21+ echo $result, PHP_EOL;
2222
2323$result = strlen("Hello World");
24- print $result . PHP_EOL;
24+ echo $result, PHP_EOL;
2525?>
2626]]>
2727 </programlisting >
@@ -38,7 +38,7 @@ print $result . PHP_EOL;
3838 For a single call that is not especially useful. It becomes useful when multiple calls are chained together.
3939 That is, the following two code fragments are logically equivalent:
4040 <example >
41- <title >Chaining |> calls</title >
41+ <title >Chaining |> calls</title >
4242 <programlisting role =" php" >
4343<![CDATA[
4444<?php
@@ -48,15 +48,15 @@ $result = "PHP Rocks"
4848 |> (fn($x) => array_map(strtoupper(...), $x))
4949 |> (fn($x) => array_filter($x, fn($v) => $v != 'O'))
5050;
51- print $result . PHP_EOL;
51+ echo $result, PHP_EOL;
5252
5353$temp = "PHP Rocks";
5454$temp = htmlentities($temp);
5555$temp = str_split($temp);
5656$temp = array_map(strtoupper(...), $temp);
5757$temp = array_filter($temp, fn($v) => $v != 'O');
5858$result = $temp;
59- print $result . PHP_EOL;
59+ echo $result, PHP_EOL;
6060?>
6161]]>
6262 </programlisting >
0 commit comments