exit

(PHP 4, PHP 5, PHP 7)

exit锟斤拷锟揭伙拷锟斤拷锟较拷锟斤拷锟斤拷顺锟斤拷锟角帮拷疟锟�

说锟斤拷

exit ([ string $status ] ) : void
exit ( int $status ) : void

锟斤拷止锟脚憋拷锟斤拷执锟叫★拷 锟斤拷锟杰碉拷锟斤拷锟斤拷 exit()锟斤拷 Shutdown锟斤拷锟斤拷 锟皆硷拷 object destructors 锟斤拷锟角会被执锟叫★拷

exit 锟角革拷锟斤法锟结构锟斤拷锟斤拷锟矫伙拷锟� status 锟斤拷锟斤拷要锟斤拷锟诫,锟斤拷锟斤拷省锟斤拷圆锟斤拷锟脚★拷

锟斤拷锟斤拷

status

锟斤拷锟� status 锟斤拷一锟斤拷锟街凤拷锟斤拷锟斤拷锟斤拷锟剿筹拷之前锟矫猴拷锟斤拷锟斤拷锟接� status 锟斤拷

锟斤拷锟� status 锟斤拷一锟斤拷 integer锟斤拷锟斤拷值锟斤拷锟斤拷为锟剿筹拷状态锟诫,锟斤拷锟揭诧拷锟结被锟斤拷印锟斤拷锟斤拷锟� 锟剿筹拷状态锟斤拷应锟斤拷锟节凤拷围0锟斤拷254锟斤拷锟斤拷应使锟矫憋拷PHP锟斤拷锟斤拷锟斤拷锟剿筹拷状态锟斤拷255锟斤拷 状态锟斤拷0锟斤拷锟节成癸拷锟斤拷止锟斤拷锟斤拷

锟斤拷锟斤拷值

没锟叫凤拷锟斤拷值锟斤拷

锟斤拷锟斤拷

Example #1 exit() 锟斤拷锟斤拷

<?php

$filename 
'/path/to/data-file';
$file fopen($filename'r')
    or exit(
"unable to open file ($filename)");

?>

Example #2 exit() 状态锟斤拷锟斤拷锟斤拷

<?php

//exit program normally
exit;
exit();
exit(
0);

//exit with an error code
exit(1);
exit(
0376); //octal

?>

Example #3 锟斤拷锟斤拷锟斤拷危锟絊hutdown锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟结被执锟斤拷

<?php
class Foo
{
    public function 
__destruct()
    {
        echo 
'Destruct: ' __METHOD__ '()' PHP_EOL;
    }
}

function 
shutdown()
{
    echo 
'Shutdown: ' __FUNCTION__ '()' PHP_EOL;
}

$foo = new Foo();
register_shutdown_function('shutdown');

exit();
echo 
'This will not be output.';
?>

锟斤拷锟斤拷锟斤拷锟教伙拷锟斤拷锟斤拷锟�

 Shutdown: shutdown()
 Destruct: Foo::__destruct()
 

注锟斤拷

Note: 锟斤拷为锟斤拷一锟斤拷锟斤拷锟皆癸拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷一锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟杰憋拷 锟缴变函锟斤拷 锟斤拷锟矫★拷

Note:

锟斤拷锟斤法锟结构锟斤拷同锟斤拷 die()锟斤拷

锟轿硷拷