Page 1 of 2 12 LastLast
Results 1 to 10 of 17
  1. #1
    Join Date
    May 2012
    Location
    Delft, the Netherlands
    Posts
    7
    Plugin Contributions
    0

    help question end tags in PHP comments

    Hi all,

    In many (!) files I encounter php end tags (?>) after the start of a single line comment (//). On many occasions this is not a problem in practice, because the first statement after that is a php open tag (<?php) which is ignored by php. But in at least one case I could trace curious output back to such a missed php end. Are you aware of this problem? I am using PHP 5.3.8.

    Yours,

    andriks

  2. #2
    Join Date
    Feb 2005
    Location
    Lansing, Michigan USA
    Posts
    18,041
    Plugin Contributions
    1

  3. #3
    Join Date
    Jul 2005
    Location
    Upstate NY
    Posts
    20,981
    Plugin Contributions
    25

    Default Re: end tags in PHP comments

    The comment marks // do not hide the PHP end tag from processing.

  4. #4
    Join Date
    May 2012
    Location
    Delft, the Netherlands
    Posts
    7
    Plugin Contributions
    0

    Default Re: end tags in PHP comments

    Quote Originally Posted by gjh42 View Post
    The comment marks // do not hide the PHP end tag from processing.
    Oh yes they do. At least in my configuration. Try the following:
    <html>
    <head>
    <title>PHP test page</title>
    </head>
    <body>
    <?php // the first line is always printed:
    echo "<h1>Welcome to the PHP test page</h1>";
    // PHP ends? ?>
    echo "<p>What is on this line?</p>";
    <?php // if PHP did not end the previous line will only contain the paragraph, not the whole echo.
    echo "<p>Back in PHP?</p>";
    ?>
    <?php // the next line is always printed:
    echo "<h2>Another PHP test</h2>";
    // PHP ends? ?>
    <?php echo "<p>Because we switch back to PHP immediately after the missed end tag, we are okay here.</p>"; ?>
    <?php phpinfo(); ?>
    </body>
    </html>


    Notice how the second echo is displayed!

    Yours,

    Andriks

  5. #5
    Join Date
    May 2012
    Location
    Delft, the Netherlands
    Posts
    7
    Plugin Contributions
    0

    Default Re: end tags in PHP comments

    Another problem. I refer to tags in the middle of files. See my code in the answer to gjh42.

    Andriks

  6. #6
    Join Date
    Apr 2009
    Location
    In a traffic jam
    Posts
    1,982
    Plugin Contributions
    1

    Default Re: end tags in PHP comments

    Those comments will stop all the php on that line after them being processed.

    It is just very bad coding. And I should mention, it does not occur in the default Zen Cart files. This line:

    Code:
    // PHP ends? ?>
    Should be:

    Code:
     
    // PHP ends?
    ?>
    So, either there has been a problem in uploading files where the line-breaks have got messed up for whatever reason. Or the code is just plain wrong. IMO.

    Either way it needs to sorted out. I am guessing that the code in question comes from a template or a module rather than the core Zen Cart files?

  7. #7
    Join Date
    Jul 2005
    Location
    Upstate NY
    Posts
    20,981
    Plugin Contributions
    25

    Default Re: end tags in PHP comments

    Yes, testing in actual PHP/HTML output does behave as you described. This is apparently a bug in Notepad++, as it shows that the trailing ?> is active and the following line is outside PHP.

  8. #8
    Join Date
    Jul 2005
    Location
    Upstate NY
    Posts
    20,981
    Plugin Contributions
    25

    Default Re: end tags in PHP comments

    Very weird... if you look closely at the output of the test page, you will see (at least I do) that the output is not proper HTML: the <h1> is not in h1 formatting, and the closing quote and end-of-line semicolon print when they should not. Duplicating the first echo line results in the second echo being formatted as an h1 heading.

    There is lots of stuff going on that should not be happening with PHP to HTML output... don't have time to elaborate at the moment, have to go off to breakfast.
    Welcome to the PHP test page'; echo "
    Welcome to the PHP test page
    "; // PHP ends? ?> echo "

    What is on this line?
    "; Back in PHP?

    "; ?> Another PHP test"; // PHP ends? ?> Because we switch back to PHP immediately after the missed end tag, we are okay here.

    "; ?>

  9. #9
    Join Date
    Apr 2009
    Location
    In a traffic jam
    Posts
    1,982
    Plugin Contributions
    1

    Default Re: end tags in PHP comments

    Not really all that weird. PHP manual says:

    The "one-line" comment styles only comment to the end of the line or the current block of PHP code, whichever comes first. This means that HTML code after // ... ?> or # ... ?> WILL be printed: ?> breaks out of PHP mode and returns to HTML mode, and // or # cannot influence that. If the asp_tags configuration directive is enabled, it behaves the same with // %> and # %>. However, the </script> tag doesn't break out of PHP mode in a one-line comment.
    The closing quote and semi-colon print because those are not code in php mode.

    So, I have to hold my hand up and say my previous comment was inaccurate. But when I run your code I see exactly what I would expect output to the page. And I'd add that it is pretty common practice to comment either on separate lines or after the end of a line of code.

    The source code I get when I run that is:

    Code:
    <html>
    <head>
    <title>PHP test page</title>
    </head>
    <body>
    <h1>Welcome to the PHP test page</h1>echo "<p>What is on this line?</p>";
    <p>Back in PHP?</p><h2>Another PHP test</h2><p>Because we switch back to PHP immediately after the missed end tag, we are okay here.</p></body>
    </html>
    Which seems completely right. I exclude the php info section as it just introduces two <html> tags to the document
    Last edited by niccol; 3 Jun 2012 at 03:41 PM.

  10. #10
    Join Date
    May 2012
    Location
    Delft, the Netherlands
    Posts
    7
    Plugin Contributions
    0

    Default Re: end tags in PHP comments

    Quote Originally Posted by niccol View Post
    Those comments will stop all the php on that line after them being processed.

    It is just very bad coding. And I should mention, it does not occur in the default Zen Cart files.
    It does occur in the template_default files. The results of a simple scan on the occurrence of ?> after // yields:

    includes\templates\template_default\templates\tpl_account_default.php
    warning: PHP end tag found in comment on line 74 !
    warning: PHP end tag found in comment on line 80 !
    warning: PHP end tag found in comment on line 83 !
    97 lines.

    includes\templates\template_default\templates\tpl_account_history_info_default.p hp
    warning: PHP end tag found in comment on line 135 !
    150 lines.

    includes\templates\template_default\templates\tpl_checkout_confirmation_default. php
    warning: PHP end tag found in comment on line 111 !
    warning: PHP end tag found in comment on line 112 !
    warning: PHP end tag found in comment on line 129 !
    warning: PHP end tag found in comment on line 149 !
    warning: PHP end tag found in comment on line 153 !
    warning: PHP end tag found in comment on line 160 !
    184 lines.

    includes\templates\template_default\templates\tpl_checkout_payment_default.php
    warning: PHP end tag found in comment on line 41 !
    warning: PHP end tag found in comment on line 55 !
    warning: PHP end tag found in comment on line 99 !
    warning: PHP end tag found in comment on line 200 !
    210 lines.

    includes\templates\template_default\templates\tpl_document_general_info_display. php
    warning: PHP end tag found in comment on line 111 !
    warning: PHP end tag found in comment on line 112 !
    228 lines.

    includes\templates\template_default\templates\tpl_document_product_info_display. php
    warning: PHP end tag found in comment on line 111 !
    warning: PHP end tag found in comment on line 112 !
    229 lines.

    includes\templates\template_default\templates\tpl_ezpages_bar_footer.php
    warning: PHP end tag found in comment on line 23 !
    24 lines.

    includes\templates\template_default\templates\tpl_ezpages_bar_header.php
    warning: PHP end tag found in comment on line 23 !
    25 lines.

    includes\templates\template_default\templates\tpl_featured_products_default.php
    warning: PHP end tag found in comment on line 82 !
    83 lines.

    includes\templates\template_default\templates\tpl_index_categories.php
    warning: PHP end tag found in comment on line 63 !
    118 lines.

    includes\templates\template_default\templates\tpl_index_product_list.php
    warning: PHP end tag found in comment on line 35 !
    warning: PHP end tag found in comment on line 154 !
    211 lines.

    includes\templates\template_default\templates\tpl_login_default.php
    warning: PHP end tag found in comment on line 23 !
    warning: PHP end tag found in comment on line 31 !
    100 lines.

    includes\templates\template_default\templates\tpl_modules_attributes.php
    warning: PHP end tag found in comment on line 17 !
    67 lines.

    includes\templates\template_default\templates\tpl_modules_listing_display_order. php
    warning: PHP end tag found in comment on line 27 !
    35 lines.

    includes\templates\template_default\templates\tpl_modules_products_quantity_disc ounts.php
    warning: PHP end tag found in comment on line 82 !
    83 lines.

    includes\templates\template_default\templates\tpl_page_not_found_default.php
    warning: PHP end tag found in comment on line 39 !
    55 lines.

    includes\templates\template_default\templates\tpl_products_all_default.php
    warning: PHP end tag found in comment on line 84 !
    85 lines.

    includes\templates\template_default\templates\tpl_products_new_default.php
    warning: PHP end tag found in comment on line 83 !
    84 lines.

    includes\templates\template_default\templates\tpl_product_free_shipping_info_dis play.php
    warning: PHP end tag found in comment on line 111 !
    warning: PHP end tag found in comment on line 112 !
    229 lines.

    includes\templates\template_default\templates\tpl_product_info_display.php
    warning: PHP end tag found in comment on line 112 !
    warning: PHP end tag found in comment on line 113 !
    230 lines.

    includes\templates\template_default\templates\tpl_product_music_info_display.php
    warning: PHP end tag found in comment on line 111 !
    warning: PHP end tag found in comment on line 112 !
    241 lines.

    includes\templates\template_default\templates\tpl_shopping_cart_default.php
    warning: PHP end tag found in comment on line 49 !
    warning: PHP end tag found in comment on line 50 !
    232 lines.

    includes\templates\template_default\templates\tpl_site_map_default.php
    warning: PHP end tag found in comment on line 42 !
    88 lines.

    Yours,

    Andriks

 

 
Page 1 of 2 12 LastLast

Similar Threads

  1. v1.3.9h ?> missing from end of counter.php
    By Mermandamus in forum Upgrading from 1.3.x to 1.3.9
    Replies: 2
    Last Post: 28 Sep 2011, 10:58 PM
  2. php end tag missing
    By djoel in forum Upgrading from 1.3.x to 1.3.9
    Replies: 3
    Last Post: 5 May 2010, 05:55 PM
  3. code comments passed to end-user
    By Brickoneer in forum General Questions
    Replies: 8
    Last Post: 24 Mar 2008, 10:58 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •