Hi,

Nikita Popov wrote:
On Thu, Sep 7, 2017 at 2:43 PM, Andrea Faulds <a...@ajf.me> wrote:

Hi Nikita,

Nikita Popov wrote:


It also goes the other way. Whether you want to drop the newline after ?>
depends (roughly) on whether the code is control flow (drop) or trailing
output (don't drop). If the newline is not dropped anymore it doesn't mean
that the output will look nice, it's just going to be broken in a
different
way.


I understand that it should be dropped for “control flow” code (maybe not
the best term, I misunderstood what you meant at first). That's why I
suggest ignoring the following newline only for the ?> at the end of the
file, because I can't think of another place where you would have a ?> and
*not* intend output immediately after it.

So I'm not sure I understand your objection, from that standpoint. Did I
miss something?

Regards.


I'm referring to code like

<ul>
<?php foreach ($data as $value): ?>
    <li><?= $value ?></li>
<?php endforeach; ?>
</ul>

Currently this would produce the output

<ul>
    <li>Foo</li>
    <li>Bar</li>
</ul>

Without the trailing newline elision it would produce

<ul>

    <li>Foo</li>
    <li>Bar</li>

</ul>

I always assumed that this is the reason why we do this in the first place.

Ah. See, it's actually that kind of code that is my problem. A practical example would be:

<table>
    <?php foreach($rows as $row): ?>
        <tr>
            <?php foreach ($row as $column): ?>
                <td><?=htmlspecialchars($column)?></td>
            <?php endforeach; ?>
        </tr>
    <?php endforeach; ?>
</table>

which currently produces:

<table>
            <tr>
                            <td>foo</td>
                            <td>bar</td>
                    </tr>
            <tr>
                            <td>baz</td>
                            <td>qux</td>
                    </tr>
    </table>

The doubled-up indentation from missing newlines makes it into a mess. And this is even worse in practice when you have more nested control flow. Extra newlines would be fine here, but missing newlines aren't.

Thanks.

--
Andrea Faulds
https://ajf.me/

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

Reply via email to