|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[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"
}
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2026 The PHP GroupAll rights reserved. |
Last updated: Tue Oct 06 10:00:01 2026 UTC |
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.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.