Fix GH-20871: Improve error message for invalid -d options#20899
Fix GH-20871: Improve error message for invalid -d options#20899khaledalam wants to merge 4 commits intophp:masterfrom
Conversation
|
It would probably help even more if there was an indication that the parsing error happens for INI parsing, rather than parsing of the PHP code. For example, instead of "in Unknown" it could print "in INI command line parameter '-d'". Or maybe even the INI line itself. |
@iluuu1994 Thank you for the feedback! I've updated the message. The error message now clearly indicates this is INI parsing, e.g. |
| error_buf = (char *) emalloc(error_buf_len); | ||
|
|
||
| sprintf(error_buf, "%s in %s on line %" PRIu32 "\n", msg, currently_parsed_filename, zend_ini_scanner_get_lineno()); | ||
| if (strcmp(currently_parsed_filename, "Unknown") == 0 && CG(ini_parser_unbuffered_errors)) { |
There was a problem hiding this comment.
You probably want to check if (ini_filename) instead. Side-note: The if (currently_parsed_filename) { is useless because zend_ini_scanner_get_filename() never returns NULL.
| error_buf = (char *) emalloc(error_buf_len); | ||
|
|
||
| sprintf(error_buf, "%s in %s on line %" PRIu32 "\n", msg, currently_parsed_filename, zend_ini_scanner_get_lineno()); | ||
| if (strcmp(currently_parsed_filename, "Unknown") == 0 && CG(ini_parser_unbuffered_errors)) { |
There was a problem hiding this comment.
Why does this check CG(ini_parser_unbuffered_errors)?
There was a problem hiding this comment.
To distinguish CLI/FPM -d INI overrides from parse_ini_string(). in basic_functions.c it's called with unbuffered_errors = 0, while the other call sites pass 1.
| error_buf = (char *) emalloc(error_buf_len); | ||
|
|
||
| sprintf(error_buf, "%s in %s on line %" PRIu32 "\n", msg, currently_parsed_filename, zend_ini_scanner_get_lineno()); | ||
| if (strcmp(currently_parsed_filename, "Unknown") == 0 && CG(ini_parser_unbuffered_errors)) { |
There was a problem hiding this comment.
Can ini_filename be unset for any other reasons? E.g. when set in php-fpm.conf or php_value in Apache?
There was a problem hiding this comment.
The unbuffered_errors check correctly identifies CLI/FPM command-line cases. For fpm conf and Apache php_value, I think those use zend_parse_ini_file() which sets ini_filename from the file handle.
|
Hi @bukka, can you review this PR please. |
Or modified proposed version |
Description
Fixes #20871 by improving error messages for invalid
-dcommand-line options.Previously, when an invalid
-doption was passed to PHP CLI, the error message reported "Unknown on line X". This was confusing for users who don't know about PHP's internal INI handling.Changes
Zend/zend_ini_parser.yto detect CLI/FPM-doption parsing context-doptions (filename is "Unknown" andunbuffered_errorsis true), error messages now report "-d option on line 0" instead of "Unknown on line X"sapi/cli/tests/gh20871.phptto verify the fix with multiple invalid syntax scenarios