Re: One-line heredoc for better syntax highlightning
| From: | Tim Düsterhus | Date: | Mon, 19 Sep 2022 19:18:08 +0000 |
| Subject: | Re: One-line heredoc for better syntax highlightning | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-118662@lists.php.net to get a copy of this message | ||
Hi
On 9/19/22 21:04, Olle Härstedt wrote:
That looks good in isolation, but consider the following short snippet: class Foo {The closing marker of the heredoc may be indented as of PHP 7.3, so the appropriate comparison would be this: <?php class Foo {public function bar() { $query = <<<MySQL SELECT * FROM bazMySQL;}} As you can see, the heredoc breaks the reading flow completely. For
public function __construct(
private \PDO $dbConnection
) {}
public function bar()
{
$query = <<<MySQL
SELECT *
FROM baz
MySQL;
$statement = $this->dbConnection->prepare($query);
$statement->execute();
}
}
smaller SQL queries, using one line would be an improvement, I think.A condition-less SELECT should be rare, a condition-less UPDATE or DELETE even rarer. So this "improvement" would only affect a very small number of statements in the first place and I disagree with that being an improvement even for that small number of statements, because it would be inconsistent with all the other larger statements which *are* spread across multiple lines.
Also consider that the one line will look better in your color highlight editor. :)I believe that code should be readable no matter the editor it is viewed in. The suggestion fails at that. Best regards Tim Düsterhus