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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
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

Pull Requests

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-2025 The PHP Group
All rights reserved.
Last updated: Tue May 06 09:01:28 2025 UTC