using return in include files

From: Date: Tue, 23 Jan 2007 04:11:40 +0000
Subject: using return in include files
Groups: php.general 
Request: Send a blank email to php-general+get-247596@lists.php.net to get a copy of this message
I'm trying to figure out what the desired behavior is of using the return function to bail out of an include page. I did some testing, and this is what I concluded. First, I created the following file: <?php if (defined('TEST_LOADED')) { return; } define('TEST_LOADED',true); echo "blah blah blah blah<br/>"; ?> I then called it as follows: include('test.php'); include('test.php'); include('test.php'); The output is: blah blah blah blah Second, I changed the test.php file to be the following: <?php if (defined('TEST_LOADED')) { return; } define('TEST_LOADED',true); echo "blah blah blah blah<br/>"; function myFunc($test) { } ?> When I load the page now, it throws the following error: PHP Fatal error: Cannot redeclare myfunc() It appears that if there are functions in the include page that you can't use return to bail out. What is the desired functionality in this case? Is this a bug in how php handles it? or was return never designed to be used this way? Any thoughts are appreciated. -- Aaron Axelsen lists@frozenpc.net Great hosting, low prices. Modevia Web Services LLC -- http://www.modevia.com

« previous php.general (#247596) next »