On 10/30/2015 2:44 AM, Matthew Carter wrote:
> Erwin Moller <
erwinmol...@xs4all.nl> writes:
>
>> On 10/28/2015 4:29 AM, Jerry Stuckle wrote:
>>>
>>> YOU don't see any problem. Good programmers do.
>>>
>>> Just wait until you run into a problem because of it. Your tune will
>>> change. And I'm not the only one who feels this way.
>>>
>>
>> Seconded.
>> Always use the closing tag.
>>
>> <opinionated>
>> If you get into trouble because you produce output after the closing
>> tag, get another job.
>> If that is over your head, you should change jobs, not the programming
>> language (or usage of it).
>> It isn't that hard.
>> This advice from
php.net is ridiculous.
>>
>> This reminds me a lot of the curly bracket in conditional statements.
>> Some seem to think omitting them is alright for single statements.
>> It is, of course, not alright to omit them.
>> </opinionated>
>>
>> Regards,
>> Erwin Moller
>
> Other than a feeling of self righteousness, what is gained again?
A fair question.
To name a few:
- Estatics.
- No violation of the reasonable expectation that an opening tag should
be accompanied by a closing tag.
- Slightly better readable code.
- Resistance to pop-culture programming (!).
But being self-righteous is enough reason in itself, for me.
(However, that was not the reason I jumped into this thread.)
>
> Tell me, in these two sample files, which is easier to debug if the
> aforementioned use cases occurred that cause an error when the file is
> included by another file making use of header responses:
>
> ------------------File One (no closing tag, misplaced HTML)-----------
> <?php
>
> function add($a, $b) {
> return $a + $b;
> }
>
> <h1>This is my great page of addition!</h1>
>
> ------------------File Two (closing tag, extra space)-----------------
> <?php
>
> function add($a, $b) {
> return $a + $b;
> }
>
> ?>
People who include files and put whitespaces after the closing tag will
quickly see the infamous "Output created before headers bla bla, etc
etc." error.
Hmmm, HUGE PROBLEM! Now what?
We have a few choices:
1) Remove the offending whitespace, and tell the programmer NOT to do
that again.
2) Change the language, violate the logical assumption that each opening
tag should be accompanied by a closing tag.
It is beyond my understanding how anyone can opt for the second option.
What is even more flabberghasting is the fact many people are willing to
defend that crazy decision.
>
>
> Assuming both were included/required in another file, which one would
> the majority of programmers have an easier time pinpointing the error
> with? (hint: the one where the PHP error reporting would tell you
> exactly where the faulty HTML was originating, NOT the file that was
> outputting some whitespace before a header call - that error would send
> you to the header() call line, not the bad file with trailing space).
Yes, you set up this question in such a way I can only agree with your
precooked assumption. Of course the whitespace in your second example is
harder to find.
So yes, you are right in this situation.
I DO want to add that if I save a file I have been working on, I test
the results. If I see that "output created before header blabla etc
etc", I think I know where to look first.
And that is my point: It isn't hard to find this problem.
And the "solution" you are defending is plain ugly, counter-intuitive,
and introduces its own set of new possible problems.
On a sidenote: Your example is barely realistic. In each simple IDE
(well, even Notepad++) your first example will shine out with colors,
because there is HTML found where PHP is expected.
I hope you understand what I am saying.
And if some programmer REALLY has trouble avoiding whitespaces after the
closing tag, write some simple bash script, that checks for them.
(I never needed that, but it is easy to write: just match the last ?>
and see if anything follows)
>
> There have been 0 good reasons for including a closing tag (it's just too
> bad we can't actually have a '.phpdef' file type or something that
> simulates a 100% PHP only file, without dropping in and out of tags and
> just avoids the use of the <?php ?> nonsense entirely).
>
I fail, and keep failing, to see the importance of this.
We programmers have puzzles and problems to be solved daily.
Finding an unintended whitespace isn't really a big part of my daily
business......
This solves a problem that didn't have to be solved, and it made the
language uglier.
Regards,
Erwin Moller
--
"That which can be asserted without evidence, can be dismissed without
evidence."
-- Christopher Hitchens