1.2.1164. Strings With Strange Space

An invisible space may be mistaken for a normal space.

However, PHP does straight comparisons, and may fail at recognizing. This analysis reports when it finds such strange spaces inside strings.

PHP doesn’t mistake space and tables for whitespace when tokenizing the code.

This analysis doesn’t report Unicode Codepoint Notation : those are visible in the code.

<?php

// PHP 7 notation,
$a = "\u{3000}";
$b = " ";

// Displays false
var_dump($a === $b);

?>

See also Unicode spaces and disallow irregular whitespace (no-irregular-whitespace).

1.2.1164.1. Suggestions

  • Replace the odd spaces with a normal space

  • If unsecable spaces are important for presentation, add them at the templating level.

1.2.1164.2. Specs

Short name

Type/StringWithStrangeSpace

Rulesets

All, Analyze, CE, CI-checks

Exakat since

0.11.0

PHP Version

All

Severity

Minor

Time To Fix

Quick (30 mins)

Precision

Very high

Features

non-breakable-space

Examples

OpenEMR, Thelia

Available in

Entreprise Edition, Community Edition, Exakat Cloud