-
Notifications
You must be signed in to change notification settings - Fork 8k
Fix GH-20871: Improve error message for invalid -d options #20899
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Fix GH-20871: Improve error message for invalid -d options #20899
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. |
iluuu1994
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably better if this is also reviewed by somebody else. ^^ @bukka?
| 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does this check CG(ini_parser_unbuffered_errors)?
| 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can ini_filename be unset for any other reasons? E.g. when set in php-fpm.conf or php_value in Apache?
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