mirror of
https://github.com/php/php-src.git
synced 2025-08-16 05:58:45 +02:00
Nested match expression tests
Closes GH-12433
This commit is contained in:
parent
6b73fcc2b3
commit
226b92b1dc
2 changed files with 55 additions and 0 deletions
41
Zend/tests/match/046.phpt
Normal file
41
Zend/tests/match/046.phpt
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
--TEST--
|
||||||
|
Nested match expressions
|
||||||
|
--FILE--
|
||||||
|
<?php
|
||||||
|
|
||||||
|
// Nested in return expression:
|
||||||
|
$b = 'b';
|
||||||
|
echo match($b) {
|
||||||
|
'a' => 1,
|
||||||
|
'b' => match (1) {
|
||||||
|
strpos('ab', $b) => 100,
|
||||||
|
default => 15
|
||||||
|
},
|
||||||
|
default => 4
|
||||||
|
};
|
||||||
|
|
||||||
|
echo "\n";
|
||||||
|
|
||||||
|
// Nested in condition expression:
|
||||||
|
$c = 'c';
|
||||||
|
echo match($c) {
|
||||||
|
'foo' => 'bar',
|
||||||
|
match ($c) { default => 'c' } => 300
|
||||||
|
};
|
||||||
|
|
||||||
|
echo "\n";
|
||||||
|
|
||||||
|
// Nested in one of many condition expressions:
|
||||||
|
$d = 'd';
|
||||||
|
echo match($d) {
|
||||||
|
'foo' => 'bar',
|
||||||
|
match ($d) { default => 'd' },
|
||||||
|
match ($d) { default => 'e' } => 500
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
?>
|
||||||
|
--EXPECT--
|
||||||
|
100
|
||||||
|
300
|
||||||
|
500
|
14
Zend/tests/match/047.phpt
Normal file
14
Zend/tests/match/047.phpt
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
--TEST--
|
||||||
|
Match expression inside subject expression
|
||||||
|
--FILE--
|
||||||
|
<?php
|
||||||
|
|
||||||
|
echo match (match ('b') { default => 'b' }) {
|
||||||
|
'a' => 100,
|
||||||
|
'b' => 200,
|
||||||
|
'c' => 300
|
||||||
|
};
|
||||||
|
|
||||||
|
?>
|
||||||
|
--EXPECT--
|
||||||
|
200
|
Loading…
Add table
Add a link
Reference in a new issue