php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #40832 Behavior of PI end in single-line comment
Submitted: 2007-03-16 02:15 UTC Modified: 2010-12-22 16:43 UTC
From: derp at example dot com Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 5.2.1 OS: Linux 2.4.26-gentoo-r7
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: derp at example dot com
New email:
PHP Version: OS:

 

 [2007-03-16 02:15 UTC] derp at example dot com
Description:
------------
When a processing instruction end (PIE), i.e., "?>", is encountered in a single-line comment, the PHP parser should handle it more intelligently, thus:

If the PIE would, when outside single-line comment context (SLCC), not mark the end of the current PHP code block (e.g., if it occurred inside a string literal), it should not, when inside SLCC, mark the end of the code block.

---

The above represents a compromise suggestion.  I feel the semantics of comments ought to be the same as those in, e.g., C, Perl; i.e., comment text should be naively stripped from the input stream seen by the parser.


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-12-22 13:21 UTC] johannes@php.net
-Status: Open +Status: Bogus -Package: Feature/Change Request +Package: *General Issues
 [2010-12-22 13:21 UTC] johannes@php.net
The behavior is needed to allow using single line comments while embedding PHP in HTML like in

   <h1><?php echio $title; // comment ?></h1>

Your compromise won't work as it break valid code like

   <?php if ($cond) { ?><h1>TRUE</h1><?php } ?>
 [2010-12-22 16:43 UTC] derp at example dot com
-: josh.helzer@gmail.com +: derp at example dot com
 [2010-12-22 16:43 UTC] derp at example dot com
re. [2010-12-22 12:21 UTC] johannes@php.net:

Haha, I had forgotten that I'd ever used PHP, let alone filed any bugs.  I suppose it's great that you still care, but you've misunderstood:

Consider

#! /usr/bin/php
<?php "abc ?>"; ?>
I am output!

the output is

I am output!

but, if the code above is changed to

#! /usr/bin/php
<?php //"abc ?>"; ?>
I am output!

the output becomes:

"; ?>
I am output!

Now do you see what I was talking about?  The two characters ?> that were formerly part of a string literal, and therefore not recognized as a processing instruction end, suddenly start behaving as a PI-end when the string literal has been commented out.

Your example has nothing to do with my suggestion (if you read carefully).
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sat Nov 29 18:00:01 2025 UTC