php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #15376 Can't exit an include file from function
Submitted: 2002-02-04 23:11 UTC Modified: 2010-12-31 22:36 UTC
Votes:2
Avg. Score:3.5 ± 0.5
Reproduced:2 of 2 (100.0%)
Same Version:0 (0.0%)
Same OS:1 (50.0%)
From: sgarner at expio dot co dot nz Assigned:
Status: Wont fix Package: Scripting Engine problem
PHP Version: 4.1.0 OS: Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: sgarner at expio dot co dot nz
New email:
PHP Version: OS:

 

 [2002-02-04 23:11 UTC] sgarner at expio dot co dot nz
It would be nice if a separate statement or function was used to exit include files, instead of re-using the "return" statement for this purpose.

Take the following example. In test1.php say I have:

<?
include("./test2.php");
echo "Foo";
?>

And in test2.php I have:

<?
function croak ($msg)
{
  echo $msg;
  return false;
}

mysql_connect(...) or croak("Can't connect");
mysql_select_db("foobar") or croak("Can't open DB");
?>

This doesn't work, of course. The return statement only returns from the function and the include file continues processing. One instead has to do something tedious like:

<?
if (!mysql_connect(...))
{
   echo "Can't connect";
   return false;
}
if (!mysql_select_db(...))
{
   echo "Can't open DB";
   return false;
}
?>

Hence I propose the addition of a new statement, which I will call "stop", which exits from the current include file. Then test2.php would look like:

<?
function croak ($msg)
{
  echo $msg;
  stop;
}

mysql_connect(...) or croak("Can't connect");
mysql_select_db("foobar") or croak("Can't open DB");
?>

Just an idea :-)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-12-31 22:36 UTC] jani@php.net
-Status: Open +Status: Wont fix -Package: Feature/Change Request +Package: *General Issues
 [2010-12-31 22:36 UTC] jani@php.net
Return is fine.
 [2010-12-31 22:36 UTC] jani@php.net
-Package: *General Issues +Package: Scripting Engine problem
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 23:01:28 2024 UTC