1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 08:12:21 +01:00
Files
archived-php-src/Zend/tests/pipe_operator/exception_interruption.phpt
Larry Garfield 1c09c0c832 RFC: Pipe operator (#17118)
Co-authored-by: Gina Peter Banyard <girgias@php.net>
Co-authored-by: Arnaud Le Blanc <arnaud.lb@gmail.com>
Co-authored-by: Tim Düsterhus <tim@tideways-gmbh.com>
2025-06-10 09:59:43 +02:00

38 lines
826 B
PHP

--TEST--
A pipe interrupted by an exception, to demonstrate correct order of execution.
--FILE--
<?php
function foo() { echo __FUNCTION__, PHP_EOL; return 1; }
function bar() { echo __FUNCTION__, PHP_EOL; return false; }
function baz($in) { echo __FUNCTION__, PHP_EOL; return $in; }
function quux($in) { echo __FUNCTION__, PHP_EOL; throw new \Exception('Oops'); }
try {
$result = foo()
|> (bar() ? baz(...) : quux(...))
|> var_dump(...);
}
catch (Throwable $e) {
echo $e::class, ": ", $e->getMessage(), PHP_EOL;
}
try {
$result = foo()
|> (throw new Exception('Break'))
|> (bar() ? baz(...) : quux(...))
|> var_dump(...);
}
catch (Throwable $e) {
echo $e::class, ": ", $e->getMessage(), PHP_EOL;
}
?>
--EXPECTF--
foo
bar
quux
Exception: Oops
foo
Exception: Break