php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #33979 require() language construct broken?
Submitted: 2005-08-03 15:34 UTC Modified: 2005-08-03 23:25 UTC
From: missingno at ifrance dot com Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.0.4 OS: WinXP
Private report: No CVE-ID: None
 [2005-08-03 15:34 UTC] 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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-08-03 16:53 UTC] sniper@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

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 23:25 UTC] missingno at ifrance dot com
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?
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat May 18 16:01:36 2024 UTC