Bug #71612 [Nab]: Set value random case change

From: Date: Wed, 24 Feb 2016 19:43:45 +0000
Subject: Bug #71612 [Nab]: Set value random case change
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-199461@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=71612&edit=1

 ID:                 71612
 User updated by:    keith at geerservices dot com
 Reported by:        keith at geerservices dot com
 Summary:            Set value random case change
 Status:             Not a bug
 Type:               Bug
 Package:            *General Issues
 Operating System:   Windows Server 2012
 PHP Version:        5.5.32
 Block user comment: N
 Private report:     N

 New Comment:

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.


Previous Comments:
------------------------------------------------------------------------
[2016-02-16 21:42:57] 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-16 21:38:14] 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:18:30] 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 20:39:21] 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 20:16:10] 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.

------------------------------------------------------------------------


The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at

    https://bugs.php.net/bug.php?id=71612


--
Edit this bug report at https://bugs.php.net/bug.php?id=71612&edit=1


Thread (7 messages)

« previous php.bugs (#199461) next »