Closed
Description
Description
This issue is visible on Apache/2.4.52, the cli works as expected however something with the sapi (apache2handler) gives you bad results. If you run the following code you will get the correct results on the first page load however if you refresh the page you will get the document incorrect matches below.
The following code:
<test.php>
<?php
// TEST-1: Functioning as expected - PASS
$subj = $unset_variable ?? null;
$result = match ($subj) {
'Some-Text' => 'Incorect-Match-1',
'Other-Text' => 'Incorect-Match-2',
default => 'Expected-Result',
};
var_dump($result); // string 'Expected-Result' (length=15)
// TEST-2: Incorrectly matches first expression - FAILS
function testFunction1()
{
$subj = $unset_variable ?? null;
$result = match ($subj) {
'Some-Text' => 'Incorect-Match-1',
'Other-Text' => 'Incorect-Match-2',
default => 'Expected-Result',
};
var_dump($result); // string 'Incorect-Match-1' (length=16)
}
testFunction1();
// TEST-3: Incorrectly matches first expression - FAILS
class TestClass1
{
public function __construct()
{
$subj = $unset_variable ?? null;
$result = match ($subj) {
'Some-Text' => 'Incorect-Match-1',
'Other-Text' => 'Incorect-Match-2',
default => 'Expected-Result',
};
var_dump($result); // string 'Incorect-Match-1' (length=16)
}
}
$test_class = new TestClass1();
// TEST-4: Functioning as expected - PASS
function testFunction2()
{
$subj = $unset_variable ?? null;
$result = match ($subj) {
'Some-Text' => 'Incorect-Match-1',
//'Other-Text' => 'Incorect-Match-2',
default => 'Expected-Result',
};
var_dump($result); // string 'Expected-Result' (length=15)
}
testFunction2();
// TEST-5: Functioning as expected - PASS
class TestClass2
{
public function __construct()
{
$subj = $unset_variable ?? null;
$result = match ($subj) {
'Some-Text' => 'Incorect-Match-1',
//'Other-Text' => 'Incorect-Match-2',
default => 'Expected-Result',
};
var_dump($result); // string 'Expected-Result' (length=15)
}
}
$test_class = new TestClass2();
### PHP Version
PHP 8.1.2
### Operating System
Ubuntu 22.04.1