php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #42657 ini_get() returns incorrect value when default is NULL
Submitted: 2007-09-13 12:28 UTC Modified: 2007-09-27 17:07 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: jcortinap at googlemail dot com Assigned: jani (profile)
Status: Closed Package: *General Issues
PHP Version: 5.2.4 OS: Win XP Pro / Win 2003 Server
Private report: No CVE-ID: None
 [2007-09-13 12:28 UTC] jcortinap at googlemail dot com
Description:
------------
This problem was found trying to set the sendmail_from directive from a script. This directive is intentionally NOT set on the php.ini (it is commented out).

According to the documentation, ini_get should return an empty string since the directive is not set, but it returns a boolean false.

When calling ini_set to set the value, it is expected to get the old value on success or FALSE on failure, and what we experience is that the setting is correctly set, but FALSE is returned.

My theory is that ini_set is working correctly returning the "old" value of the setting, but since the old value is being returned as FALSE from ini_get, this is what we get as a return from ini_set, so the problem seems to be in the ini_get function.

Tested with the same results on both 4.4.7 and 5.2.4.

Reproduce code:
---------------
// sendmail_from not set in php.ini. This should return an empty string
$value = ini_get('sendmail_from');
var_dump($value);

// sendmail_from is correctly set, so an empty string should be returned
$old_value = ini_set('sendmail_from', 'from@example.com');
var_dump($old_value);

// new value of the sendmail_from directive is correctly set
$value = ini_get('sendmail_from');
var_dump($value);


Expected result:
----------------
string(0) ""
string(0) ""
string(16) "from@example.com" 

Actual result:
--------------
bool(false)
bool(false)
string(16) "from@example.com" 

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-09-18 11:32 UTC] jani@php.net
Another note: sendmail_from is set to NULL by default (ie. if it's not set in php.ini, the value for it is NULL -> causes ini_get() to return false. This should be mentioned in the documentation.

I'm going to fix this for 5.3 (among lot of other issues with ini handling), so once docs are updated, reassign this back to me.

 [2007-09-18 11:39 UTC] jcortinap at googlemail dot com
Thank you for your reply.

The problem we are having with this, is that when we call ini_set('SMTP', 'our_server') it returns a boolean FALSE which, also according to the manual, means failure, and then there is an error being generated in our application.

How can we then differentiate a FALSE being returned from a failure or as the current value of the setting?
 [2007-09-27 17:07 UTC] jani@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.

The fix will be in PHP 5.3 and upwards.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 01:01:28 2024 UTC