Bug #71612 [Fbk->Opn]: Set value random case change

From: Date: Tue, 16 Feb 2016 21:38:16 +0000
Subject: Bug #71612 [Fbk->Opn]: Set value random case change
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-199278@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:             Feedback
+Status:             Open
 Type:               Bug
 Package:            *General Issues
 Operating System:   Windows Server 2012
 PHP Version:        5.5.32
 Block user comment: N
 Private report:     N

 New Comment:

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.


Previous Comments:
------------------------------------------------------------------------
[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.

------------------------------------------------------------------------
[2016-02-16 18:28:33] 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"
    }



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



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


Thread (7 messages)

« previous php.bugs (#199278) next »