使用类属性时PHP复杂语法(花括号)[关闭]

I am working through a book on object oriented PHP and have noticed the author using the complex syntax in some instances. In the chapter on inheritance he uses the code below:

// Declare the getSummaryLine() method
function getSummaryLine() {
// Define what the getSummaryLine() method does
     $base  = "$this->title ( {$this->producerMainName}, ";
     $base .= "{$this->producerFirstName} )";
     return $base;
}

My question is, why wouldn't you just use:

// Declare the getSummaryLine() method
function getSummaryLine() {
// Define what the getSummaryLine() method does
     return "$this->title ( $this->producerMainName, $this->producerFirstName )";
}

As both seem to return the same thing?

Forgive me if this is painfully obvious. I have read up on the PHP complex syntax in the manual but it didn't make things any clearer for me. Is it a security issue, style choice or something else entirely?

They both achieve the same thing, but the reason for the compounded statement has to do with readability. Longer concatenated strings are simply easier to read, and is nothing more than a code flavour on the authors part.

The complex bit about this has to do with evaluation. Using curly braces you can do this:

echo "This works: {$arr['key']}";

In this case, it's only a matter of style/preference.

The author may feel it's easier to read when it's spread out accross multiple lines and variables are inside curly braces.

All of these are valid.

Author may have used concatenation just for readability, long lines of code don't go nicely in books too.

You sometimes need a {} around a string from array/object when embedding placing within double quotes or else you'll see a syntax error.

// Declare the getSummaryLine() method
function getSummaryLine() {
// Define what the getSummaryLine() method does
     $base  = "$this->title ( {$this->producerMainName}, ";
     $base .= "{$this->producerFirstName} )";
     return $base;
}

OR

// Declare the getSummaryLine() method
function getSummaryLine() {
// Define what the getSummaryLine() method does
     return "{$this->title} ( {$this->producerMainName}, {$this->producerFirstName} )";
}

Or

// Declare the getSummaryLine() method
function getSummaryLine() {
// Define what the getSummaryLine() method does
     return $this->title.'( '.$this->producerMainName.', '.$this->producerFirstName.' )';
}