php / doc-en

English PHP documentation
505 stars 736 forks source link

Update PHP tags documentation #3190

Open SteveTou opened 9 months ago

SteveTou commented 9 months ago

<?phpecho"HelloWorld"?> does not work. <?php echo"HelloWorld"?> does work. (XAMPP v8.0.1) The documentation should clarify that a space (or other character, such as newline) is needed after <?php. As a language that is used regularly with HTML which allows for no space after an opening tag- <p>HelloWorld</p>, this clarity in documentation will help people not to make this mistake.

cmb69 commented 3 months ago

Well, <?php is not an opening tag since an opening tag ends with >.

SteveTou commented 3 months ago

Your statement is contradictory to the official PHP documentation which says- When PHP parses a file, it looks for opening and closing tags, which are <?php and ?> which tell PHP to start and stop interpreting the code between them. I have yet to have someone tell why my original comment is incorrect or why they think changing of the documentation should not occur. I see lots of down votes on the PHP site (maybe because my comment there is only 1/2 correct), but nobody seems to have an explanation of this issue.

damianwadley commented 3 months ago

I have yet to have someone tell why my original comment is incorrect

<?phpecho isn't an opening tag.

or why they think changing of the documentation should not occur.

That's right, nobody has said they do not think the documentation should be changed. You can tell because (a) nobody has said that, and (b) this issue is still open.

If it helps, I'll say that I do think the documentation should be updated to explicitly state that a bit of whitespace is necessary after <?php - namely, a space, tab, or newline.

Note that it's not necessary after <?= or, if short_open_tag is enabled, <?. So these work:

<?="HelloWorld"?>
<?echo"HelloWorld"?>

As a language that is used regularly with HTML which allows for no space after an opening tag

  1. PHP's opening tag is not <?php> (or <?php?>)
  2. HTML does not allow <pclass="foo"> as an opening paragraph tag
SteveTou commented 3 months ago

Thanks Damian. Five plus months seemed like an above average response time on an issue, making this noob start to feel like maybe my request was so lacking in foundational or fundamental computer science understanding, that my request didn't warrant a response. I appreciate the elaboration on the other php opening tag styles, and yes that should be clear in the documentation as well.
I'm not sure I understand what you are trying to explain in the last bit. I didn't say PHPs opening tag was anything but <?php. I don't think the fact that an attribute inside an opening tag in HTML needs to be preceded by a whitespace, has anything to do with the fact that a whitespace is not needed after the completion of the HTML opening tag. I don't want my specific request to start getting muddied with other computer programming typing rules. <?php must be followed by a whitespace or newline character, and that should be explicitly stated in the documentation, is the only point I am trying to make. Thanks again.