Sending a POST array and memory leak

Cesar

When sending an HTTP POST array of text data, for example from a web page with an HTML form and text fields, if we use as the name property of the fields the following array url_alias[id] with id being a positive integer, we receive with PHP:

[url_alias] => Array
    (
        [2644] => url-of-product-ref-123
        [1] => url-of-product-ref-224
    )

how will the server (Apache Linux, for example) handle the POST data? Will it internally prepare an array with 2645 indexes, with a null pointer to all indexes except the index: 1 and the index: 2644, or will it do in other, optimized way? Is the format above correct in terms of efficiency - it is very comfortable for PHP programming, but I am afraid of memory leakages or something.

Alex Karshin

From PHP manual:

An array in PHP is actually an ordered map. A map is a type that associates values to keys. This type is optimized for several different uses; it can be treated as an array, list (vector), hash table (an implementation of a map), dictionary, collection, stack, queue, and probably more. As array values can be other arrays, trees and multidimensional arrays are also possible.

In your example it holds only two keys with one value assigned to each.

The manual has examples on how arrays in PHP behave. For example, if you set up the following array:

$array = array(
         "a",
         "b",
    6 => "c",
         "d",
);

They keys assigned will be 0, 1, 6 and 7:

array(4) {
  [0]=>
  string(1) "a"
  [1]=>
  string(1) "b"
  [6]=>
  string(1) "c"
  [7]=>
  string(1) "d"
}

Please read the manual to learn more.

UPDATE

You are also asking how arrays are sent over HTTP. They (arrays) are not. According to W3C specification defined here:

The form data set is then encoded according to the content type specified by the enctype attribute of the FORM element.

Each enctype has it's own rules too long and extensive to be listed here. Read it there if you wish. The thing is, when PHP receives the encoded data, it automatically decodes indexed form variable names.

So, to wrap it up, the form data is encoded, sent to PHP and the decoding process is on PHP side.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related