Edit report at http://bugs.php.net/bug.php?id=15376&edit=1

 ID:                 15376
 Updated by:         [email protected]
 Reported by:        sgarner at expio dot co dot nz
 Summary:            Can't exit an include file from function
-Status:             Open
+Status:             Wont fix
 Type:               Feature/Change Request
-Package:            Feature/Change Request
+Package:            *General Issues
 Operating System:   Linux
 PHP Version:        4.1.0
 Block user comment: N
 Private report:     N

 New Comment:

Return is fine.


Previous Comments:
------------------------------------------------------------------------
[2002-02-04 23:11:49] 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 :-)

------------------------------------------------------------------------



-- 
Edit this bug report at http://bugs.php.net/bug.php?id=15376&edit=1

Reply via email to