#28025 [Com]: function redeclared when return before its declaration

From: Date: Sat, 10 Jul 2004 14:49:56 +0000
Subject: #28025 [Com]: function redeclared when return before its declaration
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-61999@lists.php.net to get a copy of this message
ID: 28025 Comment by: patrice at lazareff dot com Reported By: Christian dot Lefebvre at atosorigin dot com Status: Open Bug Type: Scripting Engine problem Operating System: linux PHP Version: 5.0.0RC1 New Comment: Same behavior if exit is used instead of return, i.e: if(defined("MY_CONSTANT")) exit; define("MY_CONSTANT", "1"); function foo() {} The only workaround seems to be using an else statement: if(defined("MY_CONSTANT") return; else { function foo() {} } how sad... Previous Comments: ------------------------------------------------------------------------ [2004-04-16 11:08:47] Christian dot Lefebvre at atosorigin dot com #18590 seems to be the same bug, but without explanation nor test case. and it's marked "no feedback" :-( ------------------------------------------------------------------------ [2004-04-16 11:04:31] Christian dot Lefebvre at atosorigin dot com Description: ------------ lot of php3 codes begin include files by a if(defined(..)) return; define(..) to simulate include_once behavior it works fine with php4, but with php5, functions declared after this return raise "cannot redeclare" error when the file is included twice. Reproduce code: --------------- t1.php : <?php include("t2.php"); toto(); include("t2.php"); toto(); ?> t2.php : <?php error_log("in t2"); if (defined("_T2_INCLUDED")) { error_log("already went there"); return; } define("_T2_INCLUDED", "1"); error_log("still in t2"); function toto() { echo "Here am I !!\n"; } ?> Expected result: ---------------- with php4 : in t2 still in t2 Here am I !! in t2 already went there Here am I !! Actual result: -------------- with php5 : in t2 still in t2 Here am I !! Fatal error: Cannot redeclare toto() (previously declared in t2.php:13) in t2.php on line 14 ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=28025&edit=1

« previous php.bugs (#61999) next »