3 ms·
The feature isn't bad, but there are several warts. The '$' is not a prefix operator on strings. The following is a syntax error: $"test"; It turns out th
by spoondan 16y ago
The feature isn't bad, but there are several warts. The '$' is not a prefix operator on strings. The following is a syntax error:
$"test";
It turns out that '$' can only operate on an identifier or another '$' expression. The '${...}' syntax, aside from being more readable and less likely to be accidentally encountered, is more like an operator:
${"test"}; // equivalent to $test
The decision to keep (and only warn against) unescaped strings past the introduction of an incompatible feature (constants) is inexcusable. It creates oddities:
$test = 'foo';
$foo = 42;
echo $test . " ${test} " . ${test} . " " . $$test . "\n";
This generates a notice and prints, "foo foo foo 42". But then:
$test = 'foo';
$foo = 42;
define('test', 'foo');
echo $test . " ${test} " . ${test} . " " . $$test . "\n";
This will print, "foo foo 42 42". (Note also the difference between the meaning of ${...} within string interpolation versus outside of it.) Is this all understandable? Sure. Is it good? No.
- wvenable 16y ago> The decision to keep (and only warn against) unescaped strings past the introduction of an incompatible feature (constants) is inexcusable. It's so easy to turn those warnings into exceptions. I don't think I've seen any project in the wild that does anything meaningful with unescaped strings.