php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #26760 conditional class declartion causes syntax error
Submitted: 2004-01-01 11:07 UTC Modified: 2004-01-12 06:37 UTC
From: eero at volotinen dot com Assigned:
Status: Closed Package: Scripting Engine problem
PHP Version: 5.0.0RC1-dev OS: *
Private report: No CVE-ID: None
 [2004-01-01 11:07 UTC] eero at volotinen dot com
Description:
------------
Latest build breaks phpbb2 forum.



Expected result:
----------------
Phpbb2 does not show anything.


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-01-01 12:06 UTC] derick@php.net
Not enough information was provided for us to be able
to handle this bug. Please re-read the instructions at
http://bugs.php.net/how-to-report.php

If you can provide more information, feel free to add it
to this bug and change the status back to "Open".

Thank you for your interest in PHP.

 [2004-01-02 02:00 UTC] eero at volotinen dot com
[01-Jan-2004 16:19:15] PHP Fatal error:  Class 'sql_db' not found in /home/apache/www/forum/phpBB2/includes/db.php on line 60

What is broken, it worked in older build.
 [2004-01-02 02:28 UTC] alan_k@php.net
Thank you for this bug report. To properly diagnose the problem, we
need a short but complete example script to be able to reproduce
this bug ourselves. 

A proper reproducing script starts with <?php and ends with ?>,
is max. 10-20 lines long and does not require any external 
resources such as databases, etc.

If possible, make the script source available online and provide
an URL to it here. Try avoid embedding huge scripts into the report.

please look at detail what is causing the problem. - or contact the support resources. www.php.net/support


 [2004-01-02 04:53 UTC] eero at volotinen dot com
[02-Jan-2004 09:19:12] PHP Parse error:  parse error in /home/apache/www/forum/phpBB2/db/mysql.php on line 27

[02-Jan-2004 09:19:12] PHP Fatal error:  Class 'sql_db' not found in /home/apache/www/forum/phpBB2/includes/db.php on line 60

Both files can be found from : http://www.linux.ncp.fi/~eero/php_error/

I think problem was started on a few days builds.
 [2004-01-02 05:00 UTC] alan_k@php.net
can you test the simple script below.. - line 27 appears to be the class definition line. 

test it with php -l test.php
(eg. syntax test it.)

.. if this works, go back to the mysql.php file, and remove chunks. (eg. methods) and syntax test it - narrowing down the problem.




<?php
if(!defined("SQL_LAYER"))
{

define("SQL_LAYER","mysql");

class sql_db
{
 var $test;
}
} // end if..

 [2004-01-02 05:07 UTC] eero at volotinen dot com
Used this test script:

<?php
if(!defined("SQL_LAYER"))
{

define("SQL_LAYER","mysql");

class sql_db
{
 var $test;
}
} // end if..
?>

Php reports error at line 7 which starts :

class sql_db ..
 [2004-01-02 05:26 UTC] alan_k@php.net
Changing title.

I suspect marcus's fix broke this.
http://news.php.net/article.php?group=php.zend-engine.cvs&article=2159
 [2004-01-02 05:56 UTC] derick@php.net
I don't think that anything is broken here. You just can't have a conditional class definition (just like you can't instantiate a class before it's declared anymore). 
 [2004-01-02 09:59 UTC] helly@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

As Derick said.
 [2004-01-05 04:00 UTC] alan_k@php.net
This appears to fix the nesting class without affecting conditional definitions.


Index: zend_compile.c
===================================================================
RCS file: /repository/ZendEngine2/zend_compile.c,v
retrieving revision 1.507
diff -u -r1.507 zend_compile.c
--- zend_compile.c	3 Jan 2004 13:51:01 -0000	1.507
+++ zend_compile.c	5 Jan 2004 09:03:04 -0000
@@ -2315,6 +2315,11 @@
 	int doing_inheritance = 0;
 	zend_class_entry *new_class_entry = emalloc(sizeof(zend_class_entry));
 	char *lcname = zend_str_tolower_dup(class_name->u.constant.value.str.val, class_name->u.constant.value.str.len);
+	
+	if (CG(active_class_entry) != NULL) {
+		efree(lcname);
+		zend_error(E_COMPILE_ERROR, "Cannot use nest class definitions");
+	}
 
 	if (!(strcmp(lcname, "self") && strcmp(lcname, "parent"))) {
 		efree(lcname);
Index: zend_language_parser.y
===================================================================
RCS file: /repository/ZendEngine2/zend_language_parser.y,v
retrieving revision 1.132
diff -u -r1.132 zend_language_parser.y
--- zend_language_parser.y	27 Dec 2003 22:59:49 -0000	1.132
+++ zend_language_parser.y	5 Jan 2004 09:03:05 -0000
@@ -168,7 +168,9 @@
 
 inner_statement:
 		statement
+	
 	|	function_declaration_statement
+	|	class_declaration_statement		
 ;
 
 

 [2004-01-05 09:24 UTC] helly@php.net
The patch has a memleak and does not work correct. Please try the following code:
php -r 'if (1) {class a{const x=1;static function f(){return 1;}}}else{class a{const x=0;static function f(){return 0;}}}echo a::x.a::f()."\n";'
php -r 'if (0) {class a{const x=1;static function f(){return 1;}}}else{class a{const x=0;static function f(){return 0;}}}echo a::x.a::f()."\n";'
Both print '00' but the first should obviously print '11'
 [2004-01-05 22:35 UTC] alan_k@php.net
Works ok here :)

it will leak memory (as it doesnt free the newly declared class).. but since it fatal errors out anyway - it should be cleared  up on exit ?????

alan@alan:/tmp$ php5 -r 'if (1) {class a{const x=1;static function f(){return
1;}}}else{class a{const x=0;static function f(){return 0;}}}echo
a::x.a::f()."\n";'
11
alan@alan:/tmp$ php5 -r 'if (0) {class a{const x=1;static function f(){return
1;}}}else{class a{const x=0;static function f(){return 0;}}}echo
a::x.a::f()."\n";'
00

 [2004-01-06 06:41 UTC] alan_k@php.net
it appears the result is dependant on CR's

This produces 11

<?php if (1) {
class a{const x=1;static function f(){return 1;}} 
} else {class a{const x=0;static function f(){return 0;}}} echo a::x.a::f()."\n";

This produces 00
<?php if (1) {
class a{const x=1;static function f(){return 1;}}} else {class a{const x=0;static function f(){return 0;}}} echo a::x.a::f()."\n";

CR before } else {


 [2004-01-06 06:49 UTC] alan_k@php.net
php -r ' if (1) { function test () { echo "1"; }} else { function test() { echo "0"; }} test();'

There is another bug here.. - the above all in one line will echo 0!)

 [2004-01-11 17:09 UTC] andi@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Apr 20 08:01:30 2024 UTC