Home  >  Article  >  Backend Development  >  How to stop script running in php

How to stop script running in php

王林
王林Original
2020-07-21 14:45:544805browse

php methods to stop script running are: return, die, exit. If exit is used in a function, it means exiting the function. If it is used in a script, it means the script stops execution. Return is used in functions to return to the place where the function is called, and in scripts to return to the place where the script is included.

How to stop script running in php

Terminating script execution refers to telling the PHP engine through a statement that other statements after this statement do not need to be executed.

(Recommended tutorial: php tutorial)

PHP provides three ways to terminate script execution: return, die, exit.

Let’s introduce them separately:

exit: exit when executed. If it is in a function, it means exiting the function. If it is in a script, it means the script stops executing.

//exit;   //直接停止,不需要输出任何提示信息
//exit('stop here') ;  //带括号表示在此处终止,但是要输出提示信息
//die和exit是一样的//die;
die('stop here') ;

return: The return of the function is to return to the place where the function is called, and the return of the script is to return to the place where the script is included.

<?php
//包含demo13_ stop. php
$test = include &#39; demo13_ stop.php&#39; ;
var_ dump($test) ;
demo13_stop.php
<?php
   //终止脚本执行
   echo &#39;start&#39;;
   //return
   return &#39;*&#39;;

Code implementation:

Project configuration file: database connection information, etc.

<?php
    //项目配置文件
    return array(
           &#39;host&#39; =>&#39;localhost&#39;,
           &#39;port&#39; =>&#39;3306&#39;,
           &#39;user&#39; =>&#39;root&#39;,
           &#39;pass&#39; => &#39;root&#39;
    );

The above is the detailed content of How to stop script running in php. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn