From 084f6ab3c804c2e3959320064238494c7f352312 Mon Sep 17 00:00:00 2001
From: Niels Dossche <7771979+nielsdos@users.noreply.github.com>
Date: Sun, 26 Feb 2023 15:06:35 +0100
Subject: [PATCH 1/5] Implement GH-10024: support linting multiple files at
once using php -l
This is supported in both the CLI and CGI modes. For CLI this required
little changes.
For CGI, the tricky part was that the options parsing happens inside the
loop. This means that options passed after the -l flag were previously
simply ignored. As we now re-enter the loop we would parse the options
again, and if they are handled but don't set the script name, then CGI
will think you want to read from standard in. To keep the same "don't
parse options" behaviour I simply wrapped the options handling inside an
if.
---
sapi/cgi/cgi_main.c | 204 +++++++++++++++++++++-------------------
sapi/cgi/tests/012.phpt | 114 ++++++++++++++++++++++
sapi/cli/php_cli.c | 11 ++-
sapi/cli/tests/024.phpt | 111 ++++++++++++++++++++++
4 files changed, 340 insertions(+), 100 deletions(-)
create mode 100644 sapi/cgi/tests/012.phpt
create mode 100644 sapi/cli/tests/024.phpt
diff --git a/sapi/cgi/cgi_main.c b/sapi/cgi/cgi_main.c
index bf0f233118b1..88b13b607d6e 100644
--- a/sapi/cgi/cgi_main.c
+++ b/sapi/cgi/cgi_main.c
@@ -2268,107 +2268,109 @@ consult the installation file that came with this distribution, or visit \n\
init_request_info(request);
if (!cgi && !fastcgi) {
- while ((c = php_getopt(argc, argv, OPTIONS, &php_optarg, &php_optind, 0, 2)) != -1) {
- switch (c) {
-
- case 'a': /* interactive mode */
- printf("Interactive mode enabled\n\n");
- fflush(stdout);
- break;
-
- case 'C': /* don't chdir to the script directory */
- SG(options) |= SAPI_OPTION_NO_CHDIR;
- break;
-
- case 'e': /* enable extended info output */
- CG(compiler_options) |= ZEND_COMPILE_EXTENDED_INFO;
- break;
-
- case 'f': /* parse file */
- if (script_file) {
- efree(script_file);
- }
- script_file = estrdup(php_optarg);
- no_headers = 1;
- break;
+ if (behavior != PHP_MODE_LINT) {
+ while ((c = php_getopt(argc, argv, OPTIONS, &php_optarg, &php_optind, 0, 2)) != -1) {
+ switch (c) {
+
+ case 'a': /* interactive mode */
+ printf("Interactive mode enabled\n\n");
+ fflush(stdout);
+ break;
+
+ case 'C': /* don't chdir to the script directory */
+ SG(options) |= SAPI_OPTION_NO_CHDIR;
+ break;
+
+ case 'e': /* enable extended info output */
+ CG(compiler_options) |= ZEND_COMPILE_EXTENDED_INFO;
+ break;
+
+ case 'f': /* parse file */
+ if (script_file) {
+ efree(script_file);
+ }
+ script_file = estrdup(php_optarg);
+ no_headers = 1;
+ break;
- case 'i': /* php info & quit */
- if (script_file) {
- efree(script_file);
- }
- if (php_request_startup() == FAILURE) {
- SG(server_context) = NULL;
- php_module_shutdown();
- free(bindpath);
- return FAILURE;
- }
- if (no_headers) {
+ case 'i': /* php info & quit */
+ if (script_file) {
+ efree(script_file);
+ }
+ if (php_request_startup() == FAILURE) {
+ SG(server_context) = NULL;
+ php_module_shutdown();
+ free(bindpath);
+ return FAILURE;
+ }
+ if (no_headers) {
+ SG(headers_sent) = 1;
+ SG(request_info).no_headers = 1;
+ }
+ php_print_info(0xFFFFFFFF);
+ php_request_shutdown((void *) 0);
+ fcgi_shutdown();
+ exit_status = 0;
+ goto out;
+
+ case 'l': /* syntax check mode */
+ no_headers = 1;
+ behavior = PHP_MODE_LINT;
+ break;
+
+ case 'm': /* list compiled in modules */
+ if (script_file) {
+ efree(script_file);
+ }
+ SG(headers_sent) = 1;
+ php_printf("[PHP Modules]\n");
+ print_modules();
+ php_printf("\n[Zend Modules]\n");
+ print_extensions();
+ php_printf("\n");
+ php_output_end_all();
+ fcgi_shutdown();
+ exit_status = 0;
+ goto out;
+
+ case 'q': /* do not generate HTTP headers */
+ no_headers = 1;
+ break;
+
+ case 'v': /* show php version & quit */
+ if (script_file) {
+ efree(script_file);
+ }
+ no_headers = 1;
+ if (php_request_startup() == FAILURE) {
+ SG(server_context) = NULL;
+ php_module_shutdown();
+ free(bindpath);
+ return FAILURE;
+ }
SG(headers_sent) = 1;
SG(request_info).no_headers = 1;
- }
- php_print_info(0xFFFFFFFF);
- php_request_shutdown((void *) 0);
- fcgi_shutdown();
- exit_status = 0;
- goto out;
-
- case 'l': /* syntax check mode */
- no_headers = 1;
- behavior = PHP_MODE_LINT;
- break;
-
- case 'm': /* list compiled in modules */
- if (script_file) {
- efree(script_file);
- }
- SG(headers_sent) = 1;
- php_printf("[PHP Modules]\n");
- print_modules();
- php_printf("\n[Zend Modules]\n");
- print_extensions();
- php_printf("\n");
- php_output_end_all();
- fcgi_shutdown();
- exit_status = 0;
- goto out;
-
- case 'q': /* do not generate HTTP headers */
- no_headers = 1;
- break;
-
- case 'v': /* show php version & quit */
- if (script_file) {
- efree(script_file);
- }
- no_headers = 1;
- if (php_request_startup() == FAILURE) {
- SG(server_context) = NULL;
- php_module_shutdown();
- free(bindpath);
- return FAILURE;
- }
- SG(headers_sent) = 1;
- SG(request_info).no_headers = 1;
-#if ZEND_DEBUG
- php_printf("PHP %s (%s) (built: %s %s) (DEBUG)\nCopyright (c) The PHP Group\n%s", PHP_VERSION, sapi_module.name, __DATE__, __TIME__, get_zend_version());
-#else
- php_printf("PHP %s (%s) (built: %s %s)\nCopyright (c) The PHP Group\n%s", PHP_VERSION, sapi_module.name, __DATE__, __TIME__, get_zend_version());
-#endif
- php_request_shutdown((void *) 0);
- fcgi_shutdown();
- exit_status = 0;
- goto out;
-
- case 'w':
- behavior = PHP_MODE_STRIP;
- break;
-
- case 'z': /* load extension file */
- zend_load_extension(php_optarg);
- break;
-
- default:
- break;
+ #if ZEND_DEBUG
+ php_printf("PHP %s (%s) (built: %s %s) (DEBUG)\nCopyright (c) The PHP Group\n%s", PHP_VERSION, sapi_module.name, __DATE__, __TIME__, get_zend_version());
+ #else
+ php_printf("PHP %s (%s) (built: %s %s)\nCopyright (c) The PHP Group\n%s", PHP_VERSION, sapi_module.name, __DATE__, __TIME__, get_zend_version());
+ #endif
+ php_request_shutdown((void *) 0);
+ fcgi_shutdown();
+ exit_status = 0;
+ goto out;
+
+ case 'w':
+ behavior = PHP_MODE_STRIP;
+ break;
+
+ case 'z': /* load extension file */
+ zend_load_extension(php_optarg);
+ break;
+
+ default:
+ break;
+ }
}
}
@@ -2512,7 +2514,6 @@ consult the installation file that came with this distribution, or visit \n\
PG(during_request_startup) = 0;
if (php_lint_script(&file_handle) == SUCCESS) {
zend_printf("No syntax errors detected in %s\n", ZSTR_VAL(file_handle.filename));
- exit_status = 0;
} else {
zend_printf("Errors parsing %s\n", ZSTR_VAL(file_handle.filename));
exit_status = -1;
@@ -2581,6 +2582,11 @@ consult the installation file that came with this distribution, or visit \n\
}
}
}
+ if (behavior == PHP_MODE_LINT && argc - 1 > php_optind) {
+ php_optind++;
+ script_file = NULL;
+ continue;
+ }
break;
}
diff --git a/sapi/cgi/tests/012.phpt b/sapi/cgi/tests/012.phpt
new file mode 100644
index 000000000000..09e96c4d559e
--- /dev/null
+++ b/sapi/cgi/tests/012.phpt
@@ -0,0 +1,114 @@
+--TEST--
+multiple files syntax check
+--SKIPIF--
+
+--INI--
+display_errors=stdout
+--FILE--
+/dev/null";
+ }
+ exec($cmd, $output, $exit_code);
+ print_r($output);
+ var_dump($exit_code == 0);
+}
+
+$php = get_cgi_path();
+reset_env_vars();
+
+$filename_good = __DIR__."/012_good.test.php";
+$filename_good_escaped = escapeshellarg($filename_good);
+$filename_bad = __DIR__."/012_bad.test.php";
+$filename_bad_escaped = escapeshellarg($filename_bad);
+
+$code = '
+
+';
+
+file_put_contents($filename_bad, $code);
+
+run_and_output("$php -n -l $filename_good_escaped $filename_bad_escaped $filename_good_escaped");
+run_and_output("$php -n -l $filename_bad_escaped $filename_bad_escaped");
+run_and_output("$php -n -l $filename_bad_escaped some.unknown $filename_bad_escaped");
+run_and_output("$php -n -l $filename_bad_escaped $filename_bad_escaped some.unknown");
+
+echo "Done\n";
+?>
+--CLEAN--
+
+--EXPECTF--
+Array
+(
+ [0] => No syntax errors detected in %s012_good.test.php
+ [1] => No syntax errors detected in %s012_good.test.php
+)
+bool(true)
+Array
+(
+ [0] => No syntax errors detected in %s012_good.test.php
+ [1] => No input file specified.
+)
+bool(false)
+Array
+(
+ [0] => No syntax errors detected in %s012_good.test.php
+ [1] =>
+ [2] => Parse error: syntax error, unexpected token "private", expecting "{" in %s012_bad.test.php on line 5
+ [3] => Errors parsing %s012_bad.test.php
+ [4] => No syntax errors detected in %s012_good.test.php
+)
+bool(false)
+Array
+(
+ [0] =>
+ [1] => Parse error: syntax error, unexpected token "private", expecting "{" in %s012_bad.test.php on line 5
+ [2] => Errors parsing %s012_bad.test.php
+ [3] =>
+ [4] => Parse error: syntax error, unexpected token "private", expecting "{" in %s012_bad.test.php on line 5
+ [5] => Errors parsing %s012_bad.test.php
+)
+bool(false)
+Array
+(
+ [0] =>
+ [1] => Parse error: syntax error, unexpected token "private", expecting "{" in %s012_bad.test.php on line 5
+ [2] => Errors parsing %s012_bad.test.php
+ [3] => No input file specified.
+)
+bool(false)
+Array
+(
+ [0] =>
+ [1] => Parse error: syntax error, unexpected token "private", expecting "{" in %s012_bad.test.php on line 5
+ [2] => Errors parsing %s012_bad.test.php
+ [3] =>
+ [4] => Parse error: syntax error, unexpected token "private", expecting "{" in %s012_bad.test.php on line 5
+ [5] => Errors parsing %s012_bad.test.php
+ [6] => No input file specified.
+)
+bool(false)
+Done
diff --git a/sapi/cli/php_cli.c b/sapi/cli/php_cli.c
index c35980030585..26add8820add 100644
--- a/sapi/cli/php_cli.c
+++ b/sapi/cli/php_cli.c
@@ -734,6 +734,10 @@ static int do_cli(int argc, char **argv) /* {{{ */
break;
}
behavior=PHP_MODE_LINT;
+ /* We want to set the error exit status if at least one lint failed.
+ * If all were successful we set the exit status to 0.
+ * We already set EG(exit_status) here such that only failures set the exit status. */
+ EG(exit_status) = 0;
break;
case 'q': /* do not generate HTTP headers */
@@ -962,7 +966,6 @@ static int do_cli(int argc, char **argv) /* {{{ */
case PHP_MODE_LINT:
if (php_lint_script(&file_handle) == SUCCESS) {
zend_printf("No syntax errors detected in %s\n", php_self);
- EG(exit_status) = 0;
} else {
zend_printf("Errors parsing %s\n", php_self);
EG(exit_status) = 255;
@@ -1132,6 +1135,12 @@ static int do_cli(int argc, char **argv) /* {{{ */
if (translated_path) {
free(translated_path);
}
+ if (behavior == PHP_MODE_LINT && argc > php_optind && strcmp(argv[php_optind],"--")) {
+ script_file = NULL;
+ request_started = 0;
+ translated_path = NULL;
+ goto do_repeat;
+ }
/* Don't repeat fork()ed processes. */
if (--num_repeats && pid == getpid()) {
fprintf(stdout, "Finished execution, repeating...\n");
diff --git a/sapi/cli/tests/024.phpt b/sapi/cli/tests/024.phpt
new file mode 100644
index 000000000000..6c5a0d146e1d
--- /dev/null
+++ b/sapi/cli/tests/024.phpt
@@ -0,0 +1,111 @@
+--TEST--
+multiple files syntax check
+--SKIPIF--
+
+--FILE--
+
+';
+
+file_put_contents($filename_bad, $code);
+
+run_and_output("$php -n -l $filename_good_escaped $filename_bad_escaped $filename_good_escaped");
+run_and_output("$php -n -l $filename_bad_escaped $filename_bad_escaped");
+run_and_output("$php -n -l $filename_bad_escaped some.unknown $filename_bad_escaped");
+run_and_output("$php -n -l $filename_bad_escaped $filename_bad_escaped some.unknown");
+
+echo "Done\n";
+?>
+--CLEAN--
+
+--EXPECTF--
+Array
+(
+ [0] => No syntax errors detected in %s024_good.test.php
+ [1] => No syntax errors detected in %s024_good.test.php
+)
+int(0)
+Array
+(
+ [0] => No syntax errors detected in %s024_good.test.php
+ [1] => Could not open input file: some.unknown
+ [2] => No syntax errors detected in %s024_good.test.php
+)
+int(1)
+Array
+(
+ [0] => No syntax errors detected in %s024_good.test.php
+ [1] =>
+ [2] => Parse error: syntax error, unexpected token "private", expecting "{" in %s on line %d
+ [3] => Errors parsing %s024_bad.test.php
+ [4] => No syntax errors detected in %s024_good.test.php
+)
+int(255)
+Array
+(
+ [0] =>
+ [1] => Parse error: syntax error, unexpected token "private", expecting "{" in %s on line %d
+ [2] => Errors parsing %s024_bad.test.php
+ [3] =>
+ [4] => Parse error: syntax error, unexpected token "private", expecting "{" in %s on line %d
+ [5] => Errors parsing %s024_bad.test.php
+)
+int(255)
+Array
+(
+ [0] =>
+ [1] => Parse error: syntax error, unexpected token "private", expecting "{" in %s on line %d
+ [2] => Errors parsing %s024_bad.test.php
+ [3] => Could not open input file: some.unknown
+ [4] =>
+ [5] => Parse error: syntax error, unexpected token "private", expecting "{" in %s on line %d
+ [6] => Errors parsing %s024_bad.test.php
+)
+int(255)
+Array
+(
+ [0] =>
+ [1] => Parse error: syntax error, unexpected token "private", expecting "{" in %s on line %d
+ [2] => Errors parsing %s024_bad.test.php
+ [3] =>
+ [4] => Parse error: syntax error, unexpected token "private", expecting "{" in %s on line %d
+ [5] => Errors parsing %s024_bad.test.php
+ [6] => Could not open input file: some.unknown
+)
+int(1)
+Done
From 935a283be0a8b797df7f726c2a677c59f2cf60db Mon Sep 17 00:00:00 2001
From: Niels Dossche <7771979+nielsdos@users.noreply.github.com>
Date: Mon, 27 Feb 2023 19:57:10 +0100
Subject: [PATCH 2/5] Use goto instead of an if around the options parsing
---
sapi/cgi/cgi_main.c | 201 ++++++++++++++++++++++----------------------
1 file changed, 100 insertions(+), 101 deletions(-)
diff --git a/sapi/cgi/cgi_main.c b/sapi/cgi/cgi_main.c
index 88b13b607d6e..156599f6f9d4 100644
--- a/sapi/cgi/cgi_main.c
+++ b/sapi/cgi/cgi_main.c
@@ -2268,112 +2268,111 @@ consult the installation file that came with this distribution, or visit \n\
init_request_info(request);
if (!cgi && !fastcgi) {
- if (behavior != PHP_MODE_LINT) {
- while ((c = php_getopt(argc, argv, OPTIONS, &php_optarg, &php_optind, 0, 2)) != -1) {
- switch (c) {
-
- case 'a': /* interactive mode */
- printf("Interactive mode enabled\n\n");
- fflush(stdout);
- break;
-
- case 'C': /* don't chdir to the script directory */
- SG(options) |= SAPI_OPTION_NO_CHDIR;
- break;
-
- case 'e': /* enable extended info output */
- CG(compiler_options) |= ZEND_COMPILE_EXTENDED_INFO;
- break;
-
- case 'f': /* parse file */
- if (script_file) {
- efree(script_file);
- }
- script_file = estrdup(php_optarg);
- no_headers = 1;
- break;
+ while ((c = php_getopt(argc, argv, OPTIONS, &php_optarg, &php_optind, 0, 2)) != -1) {
+ switch (c) {
- case 'i': /* php info & quit */
- if (script_file) {
- efree(script_file);
- }
- if (php_request_startup() == FAILURE) {
- SG(server_context) = NULL;
- php_module_shutdown();
- free(bindpath);
- return FAILURE;
- }
- if (no_headers) {
- SG(headers_sent) = 1;
- SG(request_info).no_headers = 1;
- }
- php_print_info(0xFFFFFFFF);
- php_request_shutdown((void *) 0);
- fcgi_shutdown();
- exit_status = 0;
- goto out;
-
- case 'l': /* syntax check mode */
- no_headers = 1;
- behavior = PHP_MODE_LINT;
- break;
-
- case 'm': /* list compiled in modules */
- if (script_file) {
- efree(script_file);
- }
- SG(headers_sent) = 1;
- php_printf("[PHP Modules]\n");
- print_modules();
- php_printf("\n[Zend Modules]\n");
- print_extensions();
- php_printf("\n");
- php_output_end_all();
- fcgi_shutdown();
- exit_status = 0;
- goto out;
-
- case 'q': /* do not generate HTTP headers */
- no_headers = 1;
- break;
-
- case 'v': /* show php version & quit */
- if (script_file) {
- efree(script_file);
- }
- no_headers = 1;
- if (php_request_startup() == FAILURE) {
- SG(server_context) = NULL;
- php_module_shutdown();
- free(bindpath);
- return FAILURE;
- }
+ case 'a': /* interactive mode */
+ printf("Interactive mode enabled\n\n");
+ fflush(stdout);
+ break;
+
+ case 'C': /* don't chdir to the script directory */
+ SG(options) |= SAPI_OPTION_NO_CHDIR;
+ break;
+
+ case 'e': /* enable extended info output */
+ CG(compiler_options) |= ZEND_COMPILE_EXTENDED_INFO;
+ break;
+
+ case 'f': /* parse file */
+ if (script_file) {
+ efree(script_file);
+ }
+ script_file = estrdup(php_optarg);
+ no_headers = 1;
+ break;
+
+ case 'i': /* php info & quit */
+ if (script_file) {
+ efree(script_file);
+ }
+ if (php_request_startup() == FAILURE) {
+ SG(server_context) = NULL;
+ php_module_shutdown();
+ free(bindpath);
+ return FAILURE;
+ }
+ if (no_headers) {
SG(headers_sent) = 1;
SG(request_info).no_headers = 1;
- #if ZEND_DEBUG
- php_printf("PHP %s (%s) (built: %s %s) (DEBUG)\nCopyright (c) The PHP Group\n%s", PHP_VERSION, sapi_module.name, __DATE__, __TIME__, get_zend_version());
- #else
- php_printf("PHP %s (%s) (built: %s %s)\nCopyright (c) The PHP Group\n%s", PHP_VERSION, sapi_module.name, __DATE__, __TIME__, get_zend_version());
- #endif
- php_request_shutdown((void *) 0);
- fcgi_shutdown();
- exit_status = 0;
- goto out;
-
- case 'w':
- behavior = PHP_MODE_STRIP;
- break;
-
- case 'z': /* load extension file */
- zend_load_extension(php_optarg);
- break;
-
- default:
- break;
- }
+ }
+ php_print_info(0xFFFFFFFF);
+ php_request_shutdown((void *) 0);
+ fcgi_shutdown();
+ exit_status = 0;
+ goto out;
+
+ case 'l': /* syntax check mode */
+ no_headers = 1;
+ behavior = PHP_MODE_LINT;
+ break;
+
+ case 'm': /* list compiled in modules */
+ if (script_file) {
+ efree(script_file);
+ }
+ SG(headers_sent) = 1;
+ php_printf("[PHP Modules]\n");
+ print_modules();
+ php_printf("\n[Zend Modules]\n");
+ print_extensions();
+ php_printf("\n");
+ php_output_end_all();
+ fcgi_shutdown();
+ exit_status = 0;
+ goto out;
+
+ case 'q': /* do not generate HTTP headers */
+ no_headers = 1;
+ break;
+
+ case 'v': /* show php version & quit */
+ if (script_file) {
+ efree(script_file);
+ }
+ no_headers = 1;
+ if (php_request_startup() == FAILURE) {
+ SG(server_context) = NULL;
+ php_module_shutdown();
+ free(bindpath);
+ return FAILURE;
+ }
+ SG(headers_sent) = 1;
+ SG(request_info).no_headers = 1;
+#if ZEND_DEBUG
+ php_printf("PHP %s (%s) (built: %s %s) (DEBUG)\nCopyright (c) The PHP Group\n%s", PHP_VERSION, sapi_module.name, __DATE__, __TIME__, get_zend_version());
+#else
+ php_printf("PHP %s (%s) (built: %s %s)\nCopyright (c) The PHP Group\n%s", PHP_VERSION, sapi_module.name, __DATE__, __TIME__, get_zend_version());
+#endif
+ php_request_shutdown((void *) 0);
+ fcgi_shutdown();
+ exit_status = 0;
+ goto out;
+
+ case 'w':
+ behavior = PHP_MODE_STRIP;
+ break;
+
+ case 'z': /* load extension file */
+ zend_load_extension(php_optarg);
+ break;
+
+ default:
+ break;
}
}
+do_repeat:
if (script_file) {
/* override path_translated if -f on command line */
if (SG(request_info).path_translated) efree(SG(request_info).path_translated);
@@ -2585,7 +2584,7 @@ consult the installation file that came with this distribution, or visit \n\
if (behavior == PHP_MODE_LINT && argc - 1 > php_optind) {
php_optind++;
script_file = NULL;
- continue;
+ goto do_repeat;
}
break;
}
From 810632a14a3beda00c1ed5a1f52e8ed447580fe6 Mon Sep 17 00:00:00 2001
From: Niels Dossche <7771979+nielsdos@users.noreply.github.com>
Date: Wed, 28 Jun 2023 19:56:22 +0200
Subject: [PATCH 3/5] Address some comments
---
sapi/cgi/tests/012.phpt | 19 +++++++++----------
sapi/cli/php_cli.c | 4 ++--
sapi/cli/tests/024.phpt | 5 ++---
3 files changed, 13 insertions(+), 15 deletions(-)
diff --git a/sapi/cgi/tests/012.phpt b/sapi/cgi/tests/012.phpt
index 09e96c4d559e..8b1a61ba89aa 100644
--- a/sapi/cgi/tests/012.phpt
+++ b/sapi/cgi/tests/012.phpt
@@ -14,7 +14,7 @@ function run_and_output($cmd) {
}
exec($cmd, $output, $exit_code);
print_r($output);
- var_dump($exit_code == 0);
+ var_dump($exit_code);
}
$php = get_cgi_path();
@@ -33,9 +33,6 @@ echo "hi";
file_put_contents($filename_good, $code);
-run_and_output("$php -n -l $filename_good_escaped $filename_good_escaped");
-run_and_output("$php -n -l $filename_good_escaped some.unknown $filename_good_escaped");
-
$code = '
No syntax errors detected in %s012_good.test.php
[1] => No syntax errors detected in %s012_good.test.php
)
-bool(true)
+int(0)
Array
(
[0] => No syntax errors detected in %s012_good.test.php
[1] => No input file specified.
)
-bool(false)
+int(255)
Array
(
[0] => No syntax errors detected in %s012_good.test.php
@@ -81,7 +80,7 @@ Array
[3] => Errors parsing %s012_bad.test.php
[4] => No syntax errors detected in %s012_good.test.php
)
-bool(false)
+int(255)
Array
(
[0] =>
@@ -91,7 +90,7 @@ Array
[4] => Parse error: syntax error, unexpected token "private", expecting "{" in %s012_bad.test.php on line 5
[5] => Errors parsing %s012_bad.test.php
)
-bool(false)
+int(255)
Array
(
[0] =>
@@ -99,7 +98,7 @@ Array
[2] => Errors parsing %s012_bad.test.php
[3] => No input file specified.
)
-bool(false)
+int(255)
Array
(
[0] =>
@@ -110,5 +109,5 @@ Array
[5] => Errors parsing %s012_bad.test.php
[6] => No input file specified.
)
-bool(false)
+int(255)
Done
diff --git a/sapi/cli/php_cli.c b/sapi/cli/php_cli.c
index 26add8820add..546c4ba997dc 100644
--- a/sapi/cli/php_cli.c
+++ b/sapi/cli/php_cli.c
@@ -1131,14 +1131,14 @@ static int do_cli(int argc, char **argv) /* {{{ */
}
if (request_started) {
php_request_shutdown((void *) 0);
+ request_started = 0;
}
if (translated_path) {
free(translated_path);
+ translated_path = NULL;
}
if (behavior == PHP_MODE_LINT && argc > php_optind && strcmp(argv[php_optind],"--")) {
script_file = NULL;
- request_started = 0;
- translated_path = NULL;
goto do_repeat;
}
/* Don't repeat fork()ed processes. */
diff --git a/sapi/cli/tests/024.phpt b/sapi/cli/tests/024.phpt
index 6c5a0d146e1d..eedb901da73f 100644
--- a/sapi/cli/tests/024.phpt
+++ b/sapi/cli/tests/024.phpt
@@ -26,9 +26,6 @@ echo "hi";
file_put_contents($filename_good, $code);
-run_and_output("$php -n -l $filename_good_escaped $filename_good_escaped");
-run_and_output("$php -n -l $filename_good_escaped some.unknown $filename_good_escaped");
-
$code = '
Date: Thu, 29 Jun 2023 21:23:00 +0200
Subject: [PATCH 4/5] Fix output
---
sapi/cli/tests/024.phpt | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/sapi/cli/tests/024.phpt b/sapi/cli/tests/024.phpt
index eedb901da73f..bfd24679fd3c 100644
--- a/sapi/cli/tests/024.phpt
+++ b/sapi/cli/tests/024.phpt
@@ -38,12 +38,12 @@ class test
file_put_contents($filename_bad, $code);
-run_and_output("$php -n -l $filename_good_escaped $filename_good_escaped");
-run_and_output("$php -n -l $filename_good_escaped some.unknown $filename_good_escaped");
-run_and_output("$php -n -l $filename_good_escaped $filename_bad_escaped $filename_good_escaped");
-run_and_output("$php -n -l $filename_bad_escaped $filename_bad_escaped");
-run_and_output("$php -n -l $filename_bad_escaped some.unknown $filename_bad_escaped");
-run_and_output("$php -n -l $filename_bad_escaped $filename_bad_escaped some.unknown");
+run_and_output("$php -n -l $filename_good_escaped $filename_good_escaped 2>&1");
+run_and_output("$php -n -l $filename_good_escaped some.unknown $filename_good_escaped 2>&1");
+run_and_output("$php -n -l $filename_good_escaped $filename_bad_escaped $filename_good_escaped 2>&1");
+run_and_output("$php -n -l $filename_bad_escaped $filename_bad_escaped 2>&1");
+run_and_output("$php -n -l $filename_bad_escaped some.unknown $filename_bad_escaped 2>&1");
+run_and_output("$php -n -l $filename_bad_escaped $filename_bad_escaped some.unknown 2>&1");
echo "Done\n";
?>
From ee5f01c3591ff399622573bfa12825aa185c3881 Mon Sep 17 00:00:00 2001
From: Niels Dossche <7771979+nielsdos@users.noreply.github.com>
Date: Thu, 29 Jun 2023 22:24:20 +0200
Subject: [PATCH 5/5] Fix Windows
---
sapi/cgi/tests/012.phpt | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/sapi/cgi/tests/012.phpt b/sapi/cgi/tests/012.phpt
index 8b1a61ba89aa..7f981b7da8d0 100644
--- a/sapi/cgi/tests/012.phpt
+++ b/sapi/cgi/tests/012.phpt
@@ -14,6 +14,10 @@ function run_and_output($cmd) {
}
exec($cmd, $output, $exit_code);
print_r($output);
+ // Normalize Windows vs Linux exit codes. On Windows exit code -1 is actually -1 instead of 255.
+ if ($exit_code < 0) {
+ $exit_code += 256;
+ }
var_dump($exit_code);
}