Skip to content

Add ini_set() error reporting #2111

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

Closed
wants to merge 2 commits into from
Closed

Conversation

yohgaki
Copy link
Contributor

@yohgaki yohgaki commented Sep 1, 2016

Have you ever been frustrated by typo in ini_set() / ini_get() INI name?
This PR add ini_set() / ini_get() error reporting.
e.g. ini_set('does_not_exist', 1234); // Raise E_WARNING

To report INI errors, enable report_ini_error.
i.e. ini_set('report_ini_error', 1);

Travis spotted obsolete INI usage errors of our test codes
https://travis-ci.org/php/php-src/jobs/156940393#L1359
https://travis-ci.org/php/php-src/jobs/156940393#L1527
https://travis-ci.org/php/php-src/jobs/156940393#L1554
https://travis-ci.org/php/php-src/jobs/156940393#L1562

@cmb69
Copy link
Member

cmb69 commented Sep 1, 2016

Raising E_WARNING for unrecognized ini options appears to make sense, but I would not add another ini option to configure this. :-)

@yohgaki
Copy link
Contributor Author

yohgaki commented Sep 2, 2016

@cmb69 It could be
bool ini_report_error([bool $enable])
I think of this implementation. This approach has drawbacks

  • Cannot apply check easily. (For our unit test, we need to modify run-tests.php)
  • Cannot enable error reporting by default, BC. (We can disable this in php.ini-production)

However, I don't mind much as user should be able to enable error reporting during development. It could be RFC vote option.

@nicolas-grekas
Copy link
Contributor

nicolas-grekas commented Sep 2, 2016

This is a significant bc break. It's not uncommon at all to read an ini value that is defined only when some extension is enabled, without checking if the extension is loaded first. 👎 for that reason to me...

@yohgaki
Copy link
Contributor Author

yohgaki commented Sep 2, 2016

@nicolas-grekas
It's for development, not for production. Trying to set/get non-existing module's INI value is bug most likely, isn't it? (Finding such errors during development is the purpose of this patch)

Having an option for each ini_set() and ini_get() could be good option.

@nicolas-grekas
Copy link
Contributor

Looks at e.g. https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Debug/ExceptionHandler.php#L42
There is no bug here when xdebug is not installed...

@yohgaki
Copy link
Contributor Author

yohgaki commented Sep 2, 2016

@nicolas-grekas
Good example! This kind of ini_get() might be used, especially for modules like xdebug. I hope those users use @ for it.

Finding typo could be irritating. It should be easier than now. IMO.
If typo is happened on security related INI, it could be fatal.

@nikic
Copy link
Member

nikic commented Sep 2, 2016

I'm -1 here for the same reason as @nicolas-grekas. It's super common to indiscriminately set ini settings for extensions that may or may not be loaded (or may or may not have that setting in that version). I don't think we currently even have a way to check if an ini setting exists upfront.

@yohgaki
Copy link
Contributor Author

yohgaki commented Sep 2, 2016

@nikic
extension_loaded() could be used, but the code wouldn't be nice. Simply using @ would be the best resolution.

Setting INI values could be security problem, so only raise warning for ini_set()?

I'll make this a voting option.

@@ -5304,6 +5304,9 @@ PHP_FUNCTION(ini_get)
str = zend_ini_string(varname, (uint)varname_len, 0);

if (!str) {
if (PG(report_ini_error)) {
php_error_docref(NULL, E_WARNING, "INI(%s) does not exist", varname);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this message should be "INI Setting "%s" does not exist"

@dshafik
Copy link
Contributor

dshafik commented Sep 2, 2016

@yohgaki using @ to silence errors is very much frowned upon, and is slow.

Adding a ini_parameter_exists() function might be a worthwhile addition, OR make the behavior an addition parameter for ini_(set|get)(), rather than an INI setting.

Either way, it should be a E_NOTICE, not a E_WARNING — given that a nonexistent variable or constant is an E_NOTICE, which are potentially way more likely to be bugs than this.

@smalyshev smalyshev added the RFC label Sep 5, 2016
@yohgaki
Copy link
Contributor Author

yohgaki commented Sep 5, 2016

@dshafik

Adding a ini_parameter_exists() function might be a worthwhile addition, OR make the behavior an addition parameter for ini_(set|get)(), rather than an INI setting.

I like latter. ini_set($name, $value [, $ignore_error=FALSE]), ini_get($name [, $ignore_error=FALSE]). However, I expect some people will have complaint because internal functions do not allow excessive parameters. Therefore, ini_parameter_exists() may be better choice because users can emulate behavior with script.

I'll make these RFC vote option.

@mwillbanks
Copy link

Going back to @dshafik's argument, I would far prefer to see an addition of a parameter but rather than it error to throw an exception. This way I can handle it accordingly whereas having an error itself would prove to be more work by having to handle the error condition and swap error handlers.

string ini_set ( string $varname , string $newvalue [, boolean $throw = false])
string ini_get ( string $varname [, boolean $throw = false])

Now in this case, I can define how I feel about the error condition and if I want to catch for instance on a non-existence I can. I really like that this will provide some error mechanism but having the ability to throw and catch (even in real-world production code) is very useful.

@KalleZ
Copy link
Member

KalleZ commented Mar 2, 2019

Closing this due to inactivity. Please open a new PR and link to this if active work is being put back into it.

@KalleZ KalleZ closed this Mar 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants