0

Could anyone provide some sort of documentation on the differences and or benefits of using

$sql = <<<SQL
      SELECT COUNT(ParentGUID) 
      FROM siteobjects  
SQL;

Instead of using just using.

  $sql = "SELECT COUNT(ParentGUID) 
      FROM siteobjects";

Struggling to find any information on this due to searching for "<<

Your Common Sense
  • 156,878
  • 40
  • 214
  • 345

3 Answers3

1

The first one uses HEREDOC syntax. It's useful when you're working with multi-line strings and to avoid quoting problems. To solve the search issue, you can use a programming search engine that doesn't ignore special characters (like SymbolHound).

Amal Murali
  • 75,622
  • 18
  • 128
  • 150
0

There's no difference except for the fact that the HEREDOC would have white spaces in the start (because of tabulation).

h2ooooooo
  • 39,111
  • 8
  • 68
  • 102
0

That's PHP Heredocs syntax (http://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc). I prefer heredocs over simple strings because almost any IDE recognize the syntax, and it's more readable, but both options are possible.

raulmarcosl
  • 793
  • 1
  • 6
  • 10