Skip to content

Commit 5d5999e

Browse files
committed
Better console error handling, changed failed code to 254
Because 255 code is reserved for PHP itself
1 parent e30afd5 commit 5d5999e

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

var-dump-check.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55

66
const SUCCESS = 0,
77
WITH_ERRORS = 1,
8-
FAILED = 255;
8+
FAILED = 254; // 255 code is reserved to PHP itself
99

1010
if (PHP_VERSION < '5.4.0') {
11-
die("PHP Var Dump Check require PHP 5.4.0 and newer");
11+
fwrite(STDERR,"PHP Var Dump Check require PHP 5.4.0 and newer");
12+
die(FAILED);
1213
}
1314

14-
function showOptions()
15-
{
15+
function showOptions() {
1616
?>
1717
Options:
1818
--tracy Enable support for Tracy (Debugger::dump)
@@ -62,17 +62,19 @@ function showOptions()
6262
}
6363

6464
if (!$autoloadFileFound) {
65-
die(
65+
fwrite(STDERR,
6666
'You need to set up the project dependencies using the following commands:' . PHP_EOL .
6767
'curl -s http://getcomposer.org/installer | php' . PHP_EOL .
6868
'php composer.phar install' . PHP_EOL
6969
);
70+
die(FAILED);
7071
}
7172

7273
try {
7374
$settings = PhpVarDumpCheck\Settings::parseArguments($_SERVER['argv']);
7475
} catch (PhpVarDumpCheck\Exception\InvalidArgument $e) {
75-
echo "Invalid option {$e->getArgument()}" . PHP_EOL . PHP_EOL;
76+
fwrite(STDERR, "Invalid option {$e->getArgument()}" . PHP_EOL);
77+
echo PHP_EOL;
7678
showOptions();
7779
die(FAILED);
7880
}
@@ -82,6 +84,6 @@ function showOptions()
8284
$status = $check->check($settings);
8385
die($status ? SUCCESS : WITH_ERRORS);
8486
} catch (PhpVarDumpCheck\Exception\Exception $e) {
85-
echo $e->getMessage() . PHP_EOL;
87+
fwrite(STDERR, $e->getMessage() . PHP_EOL);
8688
die(FAILED);
8789
}

0 commit comments

Comments
 (0)