1.2.592. Interpolation

The following strings contain variables that are will be replaced. However, the following characters are ambiguous, and may lead to confusion.

It is advised to add curly brackets around those structures to make them non-ambiguous.

<?php

class b {
    public $b = 'c';
    function __toString() { return __CLASS__; }
}
$x = array(1 => new B());

// -> after the $x[1] looks like a 2nd dereferencing, but it is not.
print "$x[1]->b";
// displays : b->b

print "{$x[1]->b}";
// displays : c

?>

See also Double quoted.

1.2.592.1. Specs

Short name

Type/StringInterpolation

Rulesets

All, Changed Behavior, Coding conventions

Exakat since

0.8.4

PHP Version

All

Severity

Minor

Time To Fix

Quick (30 mins)

Precision

Very high

Features

string, interpolation

Available in

Entreprise Edition, Exakat Cloud