php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #36810 ini_set() returns FALSE, even upon success, if the option wasn't set in php.ini
Submitted: 2006-03-21 02:30 UTC Modified: 2013-07-31 05:43 UTC
From: djslakor at hotmail dot com Assigned: yohgaki (profile)
Status: Closed Package: *General Issues
PHP Version: 4CVS-2006-03-21 (snap) OS: win32
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: djslakor at hotmail dot com
New email:
PHP Version: OS:

 

 [2006-03-21 02:30 UTC] djslakor at hotmail dot com
Description:
------------
In my example, I wanted to modify the user_agent fopen wrapper option in order to spoof a user_agent (obviously).  In my current php.ini configuration, the user_agent line is commented out.  When issuing ini_set("user_agent", "Mozilla"), for example, the function returns false, although it succeeds.  

The documentation states the function is to return the previous value for the option, however, in this case, since the option was not set to begin with, it returns false, which indicates failure (although the call was a success).  This does not make sense.

Reproduce code:
---------------
Pre-req: user_agent must be commented out in php.ini

$blah = ini_set("user_agent", "Mozilla");

var_dump($blah);

Expected result:
----------------
I expect the function to successfully set user_agent to "Mozilla", which in this case it does, and return something other than false, which indicates failure.

[3 Sep 2002 3:54pm CEST] sniper@php.net

What's the bug here? If some ini setting is not set at all, what should be returned else than false?

Response:

Perhaps if the option is not already set, instead of returning false, it should simply return the value you just set the option to.  This would be better than indicating a failure when one doesn't exist.

Actual result:
--------------
Returns false.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-07-31 05:43 UTC] yohgaki@php.net
-Status: Open +Status: Closed -Package: Feature/Change Request +Package: *General Issues -Assigned To: +Assigned To: yohgaki
 [2013-07-31 05:43 UTC] yohgaki@php.net
It seems issue is fixed.

<?php
$blah = ini_set("user_agent", "Mozilla");

var_dump($blah);

outputs

string(0) ""
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sat May 03 15:01:28 2025 UTC