1.2.1115. Should Use Url Query Functions

PHP features several functions dedicated to processing URL’s query string.

Those functions include extra checks : for example, http_build_query() adds urlencode() call on the values, and allow for choosing the separator and the Query string format.

<?php
$data = array(
    'foo' => 'bar',
    'baz' => 'boom',
    'cow' => 'milk',
    'php' => 'hypertext processor'
);

// safe and efficient way to build a query string
echo http_build_query($data, '', '&') . PHP_EOL;

// slow way to produce a query string
foreach($data as $name => &$value) {
    $value = $name.'='.$value;
}
echo implode('&', $data) . PHP_EOL;

?>

1.2.1115.1. Suggestions

  • Use the URL query functions from PHP

1.2.1115.2. Specs

Short name

Structures/UseUrlQueryFunctions

Rulesets

All, Suggestions

Exakat since

1.9.7

PHP Version

All

Severity

Minor

Time To Fix

Quick (30 mins)

Precision

Very high

Features

url

Available in

Entreprise Edition, Exakat Cloud