From: kevin at hatry dot com
Operating system: irrelevant
PHP version: 4.3.2
PHP Bug Type: Scripting Engine problem
Bug description: return in included files as not always the same behaviour

Description:
------------
First i'll describe the more or less doented way of doing:

- When putting a return in an included file, the execution of the file
stops and returns to the parent file (all normal), but functions defined
in the included file are nontheless put in the environnement (they are
callable in the parent file). OK i understand that: functions are added in
the environnement at parsing time (so before execution time).

- When including two times the same file which defines a function, i get a
fatal error saying the function is already defined. (which is normal).

But when you mix both, ie: an included file defining a function with a
return at the beginning and that you include that file two times you dont
have the fatal error: php seems to ignore the second declarations.

Of course the example is trivial but it wotks the same if the includes are
done in separate files.

A last remark: if you add code after the return, it will never be executed
(that's normal) whereas the function will exists which is disturbing : i
spent half an hour wondering why my $GLOBALS affectation put after the
return (which was in an if statement) didnt appear even when i could use
the function !

Even if it's not considered as a bug i think it should be properly
doented.

Thanks.

Reproduce code:
---------------
<?php
// this is the included file: "inc.php" **************
return;

function dummy () { return 2; }
?>

and, the main file:
<?php
require('./inc.php');
require('./inc.php');

if( function_exists('dummy') ) { echo 'function: yes'."\n"; }
else { echo 'function: no'."\n"; }
?>

Expected result:
----------------
Fatal error: Cannot redeclare dummy() (previously declared in inc.php:5)
in inc.php on line 5


Actual result:
--------------
if the return statement is left uncommented:

function: yes

so the function exists despite the return.


if the return statement is commented:

Fatal error: Cannot redeclare dummy() (previously declared in inc.php:5)
in inc.php on line 5

which should be the normal behaviour in both cases, i think.

--
Edit bug report at [url]http://bugs.php.net/?id=26032&edit=1[/url]
--
Try a CVS snapshot (php4): [url]http://bugs.php.net/fix.php?id=26032&r=trysnapshot4[/url]
Try a CVS snapshot (php5): [url]http://bugs.php.net/fix.php?id=26032&r=trysnapshot5[/url]
Fixed in CVS: [url]http://bugs.php.net/fix.php?id=26032&r=fixedcvs[/url]
Fixed in release: [url]http://bugs.php.net/fix.php?id=26032&r=alreadyfixed[/url]
Need backtrace: [url]http://bugs.php.net/fix.php?id=26032&r=needtrace[/url]
Try newer version: [url]http://bugs.php.net/fix.php?id=26032&r=oldversion[/url]
Not developer issue: [url]http://bugs.php.net/fix.php?id=26032&r=support[/url]
Expected behavior: [url]http://bugs.php.net/fix.php?id=26032&r=notwrong[/url]
Not enough info: [url]http://bugs.php.net/fix.php?id=26032&r=notenoughinfo[/url]
Submitted twice: [url]http://bugs.php.net/fix.php?id=26032&r=submittedtwice[/url]
register_globals: [url]http://bugs.php.net/fix.php?id=26032&r=globals[/url]
PHP 3 support discontinued: [url]http://bugs.php.net/fix.php?id=26032&r=php3[/url]
Daylight Savings: [url]http://bugs.php.net/fix.php?id=26032&r=dst[/url]
IIS Stability: [url]http://bugs.php.net/fix.php?id=26032&r=isapi[/url]
Install GNU Sed: [url]http://bugs.php.net/fix.php?id=26032&r=gnused[/url]
Floating point limitations: [url]http://bugs.php.net/fix.php?id=26032&r=float[/url]