From: [EMAIL PROTECTED]
Operating system: Linux
PHP version: 4.1.0
PHP Bug Type: Feature/Change Request
Bug description: Can't exit an include file from function
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 :-)
--
Edit bug report at http://bugs.php.net/?id=15376&edit=1
--
Fixed in CVS: http://bugs.php.net/fix.php?id=15376&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=15376&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=15376&r=needtrace
Try newer version: http://bugs.php.net/fix.php?id=15376&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=15376&r=support
Expected behavior: http://bugs.php.net/fix.php?id=15376&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=15376&r=notenoughinfo
--
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, visit: http://www.php.net/unsub.php