、 ダイ、PHPの違いexit、exit(0)、exit(1)、exit( '0')、exit( '1')return of



Die Difference Php Exit



die( '1')die()およびexit()は、実際にはスクリプト実行の中止関数です。dieexitと、同じ関数を指す2つの名前、die()は、exit()関数のエイリアスです。関数は単一の引数を取り、プログラムは戻り値または文字列である可能性があり、入力パラメーターは戻り値をもたらさない可能性があります。

参考:どちらも同じですが、通常は選択性に微妙な違いがあります。



値0のexit関数に渡されて終了すると、スクリプトの実行が早期に終了することを意味し、通常はexit(名前)になります。

return is the return value die is stopped encountered an error exit directly stopped, and no subsequent operation codes, exit () may display the content. return is pure return value, but it will not run subsequent code exit (0): normal operation of the program and exit the program exit (1): abnormal operation leading to exit the program

プログラムエラーの場合、文字列を渡すことができ、通常はdie()名を使用して端末システムに出力されます。



echo '1111' exit(0) echo '2222'

同じダイ( '1')も出口( '1')を介して、出力1

$fp=fopen('./readme.txt','r') or die('You can not open the file') //In this case, if the function is called fopen returns a Boolean value false, die () will terminate the script immediately, and immediately print //The string passed to it, 'death can say a word or two.'

exit(1)はプログラムの内容を出力しません終了

echo 'begin' die('1') echo 'end' //Output begin1

exit(0)はプログラムの内容を出力しません終了



echo 'begin' exit(1) echo 'end' //Output begin

exit( '0')0およびプログラムの出力終了

echo 'begin' exit(0) echo 'end' //Output begin

exit( '1')およびプログラムの出力終了

echo 'begin' exit('0') echo 'end' //Output begin0

戻り値を返し、後続の手順は実行されず、出力値は実行されません

echo 'begin' exit('1') echo 'end' //Output begin1

総括する:

echo 'begin' return 1 echo 'end' //Output begin, the return value is not output to the screen, but returns to the upper layer