php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #9884 Using a return in an included file causes a major abnormality.
Submitted: 2001-03-20 19:45 UTC Modified: 2002-07-11 03:23 UTC
From: ceo at phester dot org Assigned:
Status: Closed Package: Scripting Engine problem
PHP Version: 4.1.0 OS: NT/Freebsd
Private report: No CVE-ID: None
 [2001-03-20 19:45 UTC] ceo at phester dot org
According to documentation and common sense, using a return inside an include, should end processing on the include and return to processing the script that called it. This is NOT so when functions or classes are declared AFTER the return line. The Following example shows 2 very stange abnormalities and it applies to functions aswell as classes...

1. functions/classes can still be declared AFTER the return line. The Declared function can be executed.

2. If The funtion/class is declared TWICE, it does not print an error. (this hold true to any sort of parse error, except errors withing the classes or functions =)

Here's the sample files:

---wierd.inc---
<?
return "Hi From wierd.inc...";

// The following should not even be processed...
function hello() {
  global $inc_var;
  echo $inc_var." 1";
}

// redeclaring the function should produce an error message
function hello() {
  global $inc_var;
  echo $inc_var." 2";
}
?>

---test.php---
<?
$inc_var = include("weird.inc");

// According the the documentation,
// this function should not exist..
hello();
?>

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-03-20 20:00 UTC] ceo at phester dot org
Sorry, i forgot to include the output of test.php, here' you go:

----output----
Hi From weird.inc... 1
 [2001-03-20 20:03 UTC] ceo at phester dot org
in my stupidity, i spelt weird.inc wrong... but you guys are smart, so i'll assume you can correct it.. =) (sorry)
 [2001-03-29 06:26 UTC] stas@php.net
Using return stops _running_ the script. However, in PHP 4,
scrips are _compiled_ in full before running. That means,
all functions, which are defined on the compile stage, will
be defined no matter what happened when the script was run.
 [2001-03-29 07:00 UTC] stas@php.net
reopened - double function definition still there.
 [2001-07-15 12:19 UTC] zeev@php.net
Fixed in CVS
 [2001-11-29 05:13 UTC] zeev@php.net
The fix was reverted, so the bug is reopened.  We'll have to try and find a better solution, if one exists.
 [2001-12-14 15:02 UTC] yohgaki@php.net
I guess status should be analyzed.
 [2002-07-11 03:23 UTC] sniper@php.net
This bug has been fixed in CVS. You can grab a snapshot of the
CVS version at http://snaps.php.net/. In case this was a documentation 
problem, the fix will show up soon at http://www.php.net/manual/.
In case this was a PHP.net website problem, the change will show
up on the PHP.net site and on the mirror sites.
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 08:01:28 2024 UTC