开发者

Special uses of this syntax in PHP? (Triple 'Angle Brackets') [duplicate]

开发者 https://www.devze.com 2023-02-27 02:40 出处:网络
This question already has answers here: Reference Guide: What does this symbol mean in PHP? (PHP Syntax)
This question already has answers here: Reference Guide: What does this symbol mean in PHP? (PHP Syntax) (24 answers) Closed 6 years ago. 开发者_JAVA技巧

Given the following code:

$myString = <<<script
   .
   .
   .
 script;

Thanks to the answers on the original version of this question, I understand <<< to be heredoc syntax, treated as double quotes without the need for escaping quotes.

Taking this a step further, how is this best exploited? Specifically, should this ease the strain of dealing with mixed quote strings containing code syntax?

i,e..

attribute="name-like string" attribute="property: 'value("value")';"

The thought is this may be useful (if implemented the way I am now guessing) especially when dealing with greater complexity and/or looking out for code injection. Again, looking for any scenarios where the heredoc for is particularly useful or exploitable.


It's Heredoc syntax: http://php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc

Its biggest virtue is that you don't have to worry about escaping quotes, since the string is not quote delimited.


It's called heredoc syntax:

A third way to delimit strings is the heredoc syntax: <<<. After this operator, an identifier is provided, then a newline. The string itself follows, and then the same identifier again to close the quotation.

Read more here.


It acts as a double qouted string, better to use double qoutes, easier to understand and easier to mantain in my eyes!

0

精彩评论

暂无评论...
验证码 换一张
取 消