Hi

On 9/19/22 21:04, Olle Härstedt wrote:
That looks good in isolation, but consider the following short snippet:

class Foo
{
     public function bar()
     {
         $query = <<<MySQL
         SELECT * FROM baz
MySQL;
     }
}

As you can see, the heredoc breaks the reading flow completely. For

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 __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

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php

Reply via email to