Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 14 additions & 11 deletions language/types/string.xml
Original file line number Diff line number Diff line change
Expand Up @@ -942,10 +942,13 @@ $arr = [
];

// Won't work, outputs: This is { fantastic}
echo "This is { $great}";
echo "This is { $great}" . PHP_EOL;

// Works, outputs: This is fantastic
echo "This is {$great}";
echo "This is {$great}" . PHP_EOL;

// To show curly braces in the output:
echo "This is {{$great}}" . PHP_EOL;

class Square {
public $width;
Expand All @@ -956,31 +959,31 @@ class Square {
$square = new Square(5);

// Works
echo "This square is {$square->width}00 centimeters wide.";
echo "This square is {$square->width}00 centimeters wide." . PHP_EOL;


// Works, quoted keys only work using the curly brace syntax
echo "This works: {$arr['key']}";
echo "This works: {$arr['key']}" . PHP_EOL;


// Works
echo "This works: {$arr[3][2]}";
echo "This works: {$arr[3][2]}" . PHP_EOL;

echo "This works: {$arr[DATA_KEY]}";
echo "This works: {$arr[DATA_KEY]}" . PHP_EOL;

// When using multidimensional arrays, always use braces around arrays
// when inside of strings
echo "This works: {$arr['foo'][2]}";
echo "This works: {$arr['foo'][2]}" . PHP_EOL;

echo "This works: {$obj->values[3]->name}";
echo "This works: {$obj->values[3]->name}" . PHP_EOL;

echo "This works: {$obj->$staticProp}";
echo "This works: {$obj->$staticProp}" . PHP_EOL;

// Won't work, outputs: C:\directory\{fantastic}.txt
echo "C:\directory\{$great}.txt";
echo "C:\directory\{$great}.txt" . PHP_EOL;

// Works, outputs: C:\directory\fantastic.txt
echo "C:\\directory\\{$great}.txt";
echo "C:\\directory\\{$great}.txt" . PHP_EOL;
?>
]]>
</programlisting>
Expand Down