ID:               33979
 User updated by:  missingno at ifrance dot com
 Reported By:      missingno at ifrance dot com
 Status:           Bogus
 Bug Type:         Scripting Engine problem
 Operating System: WinXP
 PHP Version:      5.0.4
 New Comment:

Well, the fact is, as per the documentation, return is supposed to
return to main script when processed in an included file.

Moreover, it also says that require() always read the passed file even
if its code isn't actually used.
Then why doesn't the return statement on maininc.php have any effect
and why is the second declaration for myfunc() used as the control is
supposed to have come back to testfile.php?


Previous Comments:
------------------------------------------------------------------------

[2005-08-03 16:53:37] [EMAIL PROTECTED]

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

You get the expected behaviour by putting the function declaration in
maininc.php inside the if()..else() block:

<? // maininc.php
if ($myvar == 1) { require('sndinc.php'); return; }
else { function myfunc() { echo "Exec'ed from maininc.php!!"; }
}
?>

------------------------------------------------------------------------

[2005-08-03 15:34:51] missingno at ifrance dot com

Description:
------------
I think the require language construct may be broken in PHP 5.0.4 under
Windows/Apache2 as it seems to ignore return statements in conditionnal
blocks.

Note: if you set $myvar to 0 in the code, there's no such problem.

Reproduce code:
---------------
<? // testfile.php
$myvar = 1;
include('maininc.php');
myfunc();
?>

<? // maininc.php
if ($myvar == 1) { require('sndinc.php'); return; }
function myfunc() { echo "Exec'ed from maininc.php!!"; }
?>

<? // sndinc.php
function myfunc() { echo "Second included file..."; }
?>

Expected result:
----------------
I would expect the script to simply echo "Second included file..." and
terminate.

Actual result:
--------------
Fatal error: Cannot redeclare myfunc() (previously declared in
D:\HTTPd\www\tests\maininc.php:8) in D:\HTTPd\www\tests\sndinc.php on
line 5


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=33979&edit=1

Reply via email to