php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #59070 Percentile Stat Function
Submitted: 2010-02-10 10:00 UTC Modified: 2016-05-28 05:22 UTC
From: jgrant at chks dot co dot uk Assigned: uchiyama (profile)
Status: Closed Package: stats (PECL)
PHP Version: 5.2.10 OS: Linux
Private report: No CVE-ID: None
 [2010-02-10 10:00 UTC] jgrant at chks dot co dot uk
Description:
------------
When using the "stats_stat_percentile" function, the array 
passed in is being modified, regardless of how you pass it 
in.

For example: 

$tmpArray contains:

Array
(
    [51] => 150
    [52] => 178
    [53] => 116
    [54] => 109
    [61] => 45
    [62] => 29
    [63] => 26
    [64] => 42
    [71] => 32
    [72] => 100
    [73] => 120
    [74] => 122
    [81] => 54
    [82] => 64
    [83] => 51
    [84] => 42
    [91] => 46
    [92] => 67
)

When used with the code to reproduce below, is being 
modified to the array below:

Array
(
    [0] => 26
    [1] => 29
    [2] => 32
    [3] => 42
    [4] => 42
    [5] => 45
    [6] => 46
    [7] => 51
    [8] => 54
    [9] => 64
    [10] => 67
    [11] => 100
    [12] => 109
    [13] => 116
    [14] => 120
    [15] => 122
    [16] => 150
    [17] => 178
)

Since I am not passing in the array to my function by 
reference, I would expect a 'copy' of my array to be used, 
leaving my original array intact.

Reproduce code:
---------------
$tmpArray = array("51" => 150, "52" => 178, "53" => 116, "54" => 109, "61" => 45, "62" => 29, "63" => 26, "64" => 42, "71" => 32, "72" => 100, "73" => 120, "74" => 122, "81" => 54, "82" => 64, "83" => 51, "84" => 42, "91" => 46, "92" => 67);

list($percent05, $percent95) = percentiles($tmpArray); 
print "<pre>"; print_r($tmpArray); print "</pre>";

function percentiles($newArray)
{
	$percent05 = stats_stat_percentile($newArray, 0.05);
	$percent95 = stats_stat_percentile($newArray, 0.95);
	return(array($percent05, $percent95));
}


Expected result:
----------------
Array
(
    [51] => 150
    [52] => 178
    [53] => 116
    [54] => 109
    [61] => 45
    [62] => 29
    [63] => 26
    [64] => 42
    [71] => 32
    [72] => 100
    [73] => 120
    [74] => 122
    [81] => 54
    [82] => 64
    [83] => 51
    [84] => 42
    [91] => 46
    [92] => 67
)

Actual result:
--------------
Array
(
    [0] => 26
    [1] => 29
    [2] => 32
    [3] => 42
    [4] => 42
    [5] => 45
    [6] => 46
    [7] => 51
    [8] => 54
    [9] => 64
    [10] => 67
    [11] => 100
    [12] => 109
    [13] => 116
    [14] => 120
    [15] => 122
    [16] => 150
    [17] => 178
)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-01-06 17:25 UTC] tyrael@php.net
-Package: PECL bug system +Package: stats
 [2016-01-20 23:17 UTC] y dot uchiyama dot 1015 at gmail dot com
In case of PHP 7.0.2 with stats-2.0.1, I got segmentation fault.
 [2016-05-28 00:22 UTC] uchiyama@php.net
-Status: Open +Status: Assigned -Assigned To: +Assigned To: uchiyama
 [2016-05-28 05:22 UTC] uchiyama@php.net
-Status: Assigned +Status: Closed
 [2016-05-28 05:22 UTC] uchiyama@php.net
Fixed in version 1.0.4/2.0.2
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 02:01:28 2024 UTC