php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #24226 Can't close then reopen a PHP script within class definition
Submitted: 2003-06-17 10:17 UTC Modified: 2003-06-18 06:07 UTC
From: stephane dot drouard at st dot com Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 4.3.2 OS: Lunix
Private report: No CVE-ID: None
 [2003-06-17 10:17 UTC] stephane dot drouard at st dot com
Description:
------------
I'm using Dreamweaver and it handles editable regions by inserting HTML comments. To do so within PHP code, we need to close the script and to reopen it after.
It works fine within functions (including class functions), loops, if, ...
The only case (I identified) that does not work is within class definitions.


Reproduce code:
---------------
<?
class test {
?>
<!-- comment -->
<?
  function test() {
    print 'OK';
  }
}
?>


Expected result:
----------------
It should compile

Actual result:
--------------
Parse error: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}'' in <file> on line 3

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-06-17 11:04 UTC] sniper@php.net
It might not be clear right away but this is how it's seen
by PHP:

<?
class test {
;
  function test() {
    print 'OK';
  }
}

From the manual, http://www.php.net/manual/en/language.basic-syntax.php

"The closing tag for the block will include the immediately trailing newline if one is present. Also, the closing tag automatically implies a semicolon; you do not need to have a semicolon terminating the last line of a PHP block."

 [2003-06-18 05:34 UTC] stephane dot drouard at st dot com
According to the answer, I added a variable but without terminating it by a ';':

<?
class test {
  var $dummy
?>
<!-- comment -->
<?
  function test() {
    print 'OK';
  }
}
?>

It still reports the same error, but now at line 6, the opening PHP tag.
 [2003-06-18 06:07 UTC] derick@php.net
You just can't split class definitions in PHP which is documented here:

http://docs.php.net/?q=language.oop

Derick

 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sat Nov 29 01:00:01 2025 UTC