1.2.1102. Should Preprocess Chr()

Replace literal chr() calls with their escape sequence.

chr() is a functioncall, that cannot be cached. It is only resolved at execution time. On the other hand, literal values are preprocessed by PHP and may be cached. This is a micro-optimisation.

<?php

// This is easier on PHP
$a = "\120\110\120\040 is great!";

// This is slow
$a = chr(80), chr(72), chr(80), chr(32), ' is great!';

// This would be the best with this example, but it is not always possible
$a = 'PHP is great!';

?>

See also Escape sequences.

1.2.1102.1. Suggestions

  • Use PHP string sequences, and skip chr() at execution time

1.2.1102.2. Specs

Short name

Php/ShouldPreprocess

Rulesets

All, Suggestions

Exakat since

1.1.9

PHP Version

All

Severity

Minor

Time To Fix

Quick (30 mins)

Precision

Very high

Features

preprocess

Examples

phpadsnew

Available in

Entreprise Edition, Exakat Cloud