Array collisions in php

Small note

Reading the variable max_input_vars made me learn a lot about the internal functions of PHP for handling arrays. Actually this is not a question, but rather answering my question : "Why do we really need this max_input_var". It is not localized and is actually associated with many other programming languages, not just php.

Problem:

Compare these two small php scripts:

$data = array();
for ($key = 0; $key <= 1073709056; $key += 32767){
    $data[$key] = 0;
}

You can check here . Everything is fine, nothing unexpected. Runtime close to 0.

And this is basically identical (1 difference)

$data = array();
for ($key = 0; $key <= 1073709056; $key += 32768){
    $data[$key] = 0;
}

. , . . , 3000 !

, ?

, php, .

+4
2

, , PHP (Java, Python, ASP.Net) / - . PHP - ( O(1)). , , , , -. O(n) n O (n) O (n ^ 2).

, . 32767 32768, , .

, - , php C. 2. ( 9 15 16). , , . size of the array - 1 . , - 0, 32, 64, 128, 256, ... .., , . .

, . , , , ( DOS-). $_GET, $_POST ( max_input_vars), XML, JSON.

, , :

+3

php, 32767 2 . 32768 3- ( , 4 ), .

+1

Source: https://habr.com/ru/post/1534744/


All Articles