Skip to content

Commit 0ac447d

Browse files
committed
More 'robust' way to check for undef vars
Thanks to https://www.php.net/manual/en/function.isset.php#119993
1 parent 4250a7a commit 0ac447d

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

Zend/tests/in-de-crement/incdec_undefined_vars_exception.phpt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,28 +12,28 @@ try {
1212
$x++;
1313
} catch (\Exception $e) {
1414
echo $e->getMessage(), PHP_EOL;
15-
if (!isset($x) && !@is_null($x)) { echo("UNDEF\n"); } else { var_dump($x); }
15+
if (compact('x') == []) { echo("UNDEF\n"); } else { var_dump($x); }
1616
}
1717
unset($x);
1818
try {
1919
$x--;
2020
} catch (\Exception $e) {
2121
echo $e->getMessage(), PHP_EOL;
22-
if (!isset($x) && !@is_null($x)) { echo("UNDEF\n"); } else { var_dump($x); }
22+
if (compact('x') == []) { echo("UNDEF\n"); } else { var_dump($x); }
2323
}
2424
unset($x);
2525
try {
2626
++$x;
2727
} catch (\Exception $e) {
2828
echo $e->getMessage(), PHP_EOL;
29-
if (!isset($x) && !@is_null($x)) { echo("UNDEF\n"); } else { var_dump($x); }
29+
if (compact('x') == []) { echo("UNDEF\n"); } else { var_dump($x); }
3030
}
3131
unset($x);
3232
try {
3333
--$x;
3434
} catch (\Exception $e) {
3535
echo $e->getMessage(), PHP_EOL;
36-
if (!isset($x) && !@is_null($x)) { echo("UNDEF\n"); } else { var_dump($x); }
36+
if (compact('x') == []) { echo("UNDEF\n"); } else { var_dump($x); }
3737
}
3838
unset($x);
3939
?>

Zend/tests/in-de-crement/incdec_undefined_vars_exception_use_result_op.phpt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,28 +12,28 @@ try {
1212
$y = $x++;
1313
} catch (\Exception $e) {
1414
echo $e->getMessage(), PHP_EOL;
15-
if (!isset($x) && !@is_null($x)) { echo("UNDEF\n"); } else { var_dump($x); }
15+
if (compact('x') == []) { echo("UNDEF\n"); } else { var_dump($x); }
1616
}
1717
unset($x);
1818
try {
1919
$y = $x--;
2020
} catch (\Exception $e) {
2121
echo $e->getMessage(), PHP_EOL;
22-
if (!isset($x) && !@is_null($x)) { echo("UNDEF\n"); } else { var_dump($x); }
22+
if (compact('x') == []) { echo("UNDEF\n"); } else { var_dump($x); }
2323
}
2424
unset($x);
2525
try {
2626
$y = ++$x;
2727
} catch (\Exception $e) {
2828
echo $e->getMessage(), PHP_EOL;
29-
if (!isset($x) && !@is_null($x)) { echo("UNDEF\n"); } else { var_dump($x); }
29+
if (compact('x') == []) { echo("UNDEF\n"); } else { var_dump($x); }
3030
}
3131
unset($x);
3232
try {
3333
$y = --$x;
3434
} catch (\Exception $e) {
3535
echo $e->getMessage(), PHP_EOL;
36-
if (!isset($x) && !@is_null($x)) { echo("UNDEF\n"); } else { var_dump($x); }
36+
if (compact('x') == []) { echo("UNDEF\n"); } else { var_dump($x); }
3737
}
3838
unset($x);
3939
?>

0 commit comments

Comments
 (0)