language/types/string.xml
affa37e16f562d9297e83b2e21ec416aadc8b72d
...
...
@@ -440,7 +440,7 @@ bar
440
440
</programlisting>
441
441
</example>
442
442
<example>
443
-
<title>Valid example, even if prior to PHP 7.3.0</title>
443
+
<title>Valid example, even prior to PHP 7.3.0</title>
444
444
<programlisting role="php">
445
445
<!-- This is a VALID example -->
446
446
<![CDATA[
...
...
@@ -721,11 +721,14 @@ EOT;
721
721
<?php
722
722
$juice = "apple";
723
723

724
-
echo "He drank some $juice juice.".PHP_EOL;
724
+
echo "He drank some $juice juice." . PHP_EOL;
725
+

725
726
// Unintended. "s" is a valid character for a variable name, so this refers to $juices, not $juice.
726
-
echo "He drank some juice made of $juices.";
727
+
echo "He drank some juice made of $juices." . PHP_EOL;
728
+

727
729
// Explicitly specify the end of the variable name by enclosing the reference in braces.
728
730
echo "He drank some juice made of {$juice}s.";
731
+

729
732
?>
730
733
]]>
731
734
</programlisting>
...
...
@@ -863,9 +866,9 @@ echo "This works: {$arr['key']}";
863
866
echo "This works: {$arr[4][3]}";
864
867

865
868
// This is wrong for the same reason as $foo[bar] is wrong outside a string.
866
-
// In other words, it will still work, but only because PHP first looks for a
867
-
// constant named foo; an error of level E_NOTICE (undefined constant) will be
868
-
// thrown.
869
+
// PHP first looks for a constant named foo, and throws an error if not found.
870
+
// If the constant is found, its value (and not 'foo' itself) would be used
871
+
// for the array index.
869
872
echo "This is wrong: {$arr[foo][3]}";
870
873

871
874
// Works. When using multi-dimensional arrays, always use braces around arrays
872
875