php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #71612 Set value random case change
Submitted: 2016-02-16 18:28 UTC Modified: 2016-02-24 19:43 UTC
From: keith at geerservices dot com Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 5.5.32 OS: Windows Server 2012
Private report: No CVE-ID: None
 [2016-02-16 18:28 UTC] keith at geerservices dot com
Description:
------------
Random strings in either variables, passed method variables, or array values are being lower cased periodically. This is happening at random. All of the times that this is being noticed is when the code is needing to check if a string is in an array or to grab an indexed value from the $_REQUEST var. In order to grab the $_REQUEST value by index, I have to array_change_key_case($_REQUEST) and strtolower($index).

The test case below errors for me because "Maintenance" =/= "maintenance".

Test script:
---------------
$modules = array("Dashboard", "Calendar", "Maintenance", "Service Orders", "Quotes", "Contacts");

var_dump($modules);

Expected result:
----------------
array(6) {
      [0]=>
      string(9) "Dashboard"
      [1]=>
      string(8) "Calendar"
      [2]=>
      string(11) "Maintenance"
      [3]=>
      string(14) "Service Orders"
      [4]=>
      string(6) "Quotes"
      [5]=>
      string(8) "Contacts"
    }


Actual result:
--------------
array(6) {
      [0]=>
      string(9) "Dashboard"
      [1]=>
      string(8) "Calendar"
      [2]=>
      string(11) "maintenance"
      [3]=>
      string(14) "Service Orders"
      [4]=>
      string(6) "Quotes"
      [5]=>
      string(8) "Contacts"
    }


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-02-16 20:16 UTC] ab@php.net
-Status: Open +Status: Feedback
 [2016-02-16 20:16 UTC] ab@php.net
Thanks for the report. Please re-check your code and be sure _REQUEST contains the strings you expect. If it appears to be correct, please provide a reproduce case involving _REQUEST. Your current code snippet won't reproduce the issue you refer to - var_dump is used in nearly every of over 12000 tests in the PHP's own test suite and such an issue would be discovered very quickly otherwise.

Thanks.
 [2016-02-16 20:39 UTC] keith at geerservices dot com
-Status: Feedback +Status: Open
 [2016-02-16 20:39 UTC] keith at geerservices dot com
Below is the current code for handling requests and another test case showing the issue for _REQUEST:

/**
*/
class RequestHandle {

    /**
     * Get the parameter index of the request var
     * @param $index
     * @return string|array
     */
    public static function getParameter($index){
        $value = "";
        $data  = $_REQUEST;

        if(isset($data[$index]) && !is_array($data[$index])) {
            $value = trim($data[$index]);
        } else if(isset($data[$index]) && is_array($data[$index])) {
            foreach($data[$index] as $key => $value){
                $data[$index][$key] = $value;
            }

            $value = $data[$index];
        }

        return $value;
    }
}

$_REQUEST contents: 
Array (
    [SubLaborCost] => Array
                        (
                            [CostId] => Array
                                (
                                    [0] => 466751
                                    [1] => 466752
                                    [2] => 
                                )

                            [OnSite] => Array
                                (
                                    [0] => 
                                    [1] => 
                                    [2] => 
                                )

                            [RequestForOnSite] => Array
                                (
                                    [0] => 
                                    [1] => 
                                    [2] => 
                                )

                            [LaborSelect] => Array
                                (
                                    [0] => 0
                                    [1] => 0
                                    [2] => 
                                )

                            [LaborClassification] => Array
                                (
                                    [0] => Team Leader Travel
                                    [1] => Technician Travel
                                    [2] => 
                                )

                            [RegLaborHours] => Array
                                (
                                    [0] => 3.00
                                    [1] => 3.00
                                    [2] => 
                                )

                            [RegLaborRate] => Array
                                (
                                    [0] => $77.25
                                    [1] => $51.50
                                    [2] => $0.00
                                )

                            [RegLaborTotAmt] => Array
                                (
                                    [0] => $231.75
                                    [1] => $154.50
                                    [2] => $0.00
                                )

                        )
)

$cost = RequestHandle::getParameter("SubLaborCost");

$cost Output: array()

Printing the $index variable that is inside of getParameter() gives me "sublaborcost" when it should be "SubLaborCost" like I passed.
 [2016-02-16 21:18 UTC] requinix@php.net
-Status: Open +Status: Feedback
 [2016-02-16 21:18 UTC] requinix@php.net
This kind of thing doesn't really happen. I'm sure you cropped out parts of the code for posting here - what else is involved in the process? Could this be a result of some error handling <https://3v4l.org/Mf41V> or debugging <https://3v4l.org/epnev> code accidentally modifying values? And

> In order to grab the $_REQUEST value by index, I have to array_change_key_case($_REQUEST)
> and strtolower($index).
Is that the normal code you had before or a workaround for this bug?
 [2016-02-16 21:38 UTC] keith at geerservices dot com
-Status: Feedback +Status: Open
 [2016-02-16 21:38 UTC] keith at geerservices dot com
I've never had this happen before, I posted on Stack Overflow(http://stackoverflow.com/questions/35353593/php-variable-array-values-lower-cased-periodically) first and no one else has seen this either.

The parts I cut short was the _REQUEST var as it has many form values, besides that, the code is what I use to set object properties. 

The array test case is more like:

class ModuleController{

	private   $modules = [
		"Dashboard",
		"Calendar",
		"Maintenance",
		"Service Orders",
		"Quotes",
		"Contacts"
	];

       /**
	 * Get the sorted modules
	 * @param string $sort
	 * @return array
	 */
	public function getAppModules($sort = 'ASC'){
		$arr = $this->modules;
		switch($sort){
			case 'DESC':
				arsort($arr);
				break;
			default:
				asort($arr);
				break;
		}

		return $this->modules;
	}
}

Then on a page I get the actual result I posted:
$controller = new ModuleController();
var_dump($controller->getAppModules());

One other PHP setting that is set that may be helpful is the intl extension.
 [2016-02-16 21:42 UTC] ab@php.net
-Status: Open +Status: Not a bug
 [2016-02-16 21:42 UTC] ab@php.net
Thanks for the follow up. Your reproduce cod is still incomplete, but i've tried it slightly modified using the built-in server on cli

<?php

class RequestHandle {

    /**
     * Get the parameter index of the request var
     * @param $index
     * @return string|array
     */
    public static function getParameter($index){
        $value = "";
        $data  = $_REQUEST;

        if(isset($data[$index]) && !is_array($data[$index])) {
            $value = trim($data[$index]);
        } else if(isset($data[$index]) && is_array($data[$index])) {
            foreach($data[$index] as $key => $value){
                $data[$index][$key] = $value;
            }

            $value = $data[$index];
        }

        return $value;
    }
}

$cost = RequestHandle::getParameter("SubLaborCost");
var_dump($_REQUEST, $cost);

?>

I'm running the server like

php -n -S 127.0.0.1:8080 -t bugs

And i'm requesting the URLs like 

curl 'http://127.0.0.1:8080/bug71612.php?SubLaborCost=42'
array(1) {
  ["SubLaborCost"]=>
  string(2) "42"
}
string(2) "42"

or like 

curl 'http://127.0.0.1:8080/bug71612.php?SubLaborCost\[\]=42'
<pre>array(1) {
  ["SubLaborCost"]=>
  array(1) {
    [0]=>
    string(2) "42"
  }
}
array(1) {
  [0]=>
  string(2) "42"
}

I currently don't see anything buggy with the php behaviors. Thus i'm closing this as not a bug. If you have a snippet reproducing a buggy core behavior, please feel free to reopen this ticket. Also please sure that your code is not affected by any external code and/or extensions.

Thanks.
 [2016-02-24 19:43 UTC] keith at geerservices dot com
So I was able to get this corrected and stable by updating PHP from 5.5.32 to 5.6.18 and using icuxx56 dlls instead of icuxx51 for the intl extension. I don't know if there is a known issue with icuxx51, but it may be something to look into.
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Tue Oct 06 09:00:02 2026 UTC