【发布时间】:2012-09-24 01:11:10
【问题描述】:
我对@987654322@ 和exit 的区别感到非常困惑。
大多数程序员都这样使用die。
$link = mysql_connect('localhost', 'mysql_user', 'mysql_password'); //don't see mysql_* problem it is just example
if (!$link) {
die('Could not connect: ' . mysql_error());
}
并像这样使用exit
$filename = '/path/to/data-file';
$file = fopen($filename, 'r')
or exit("unable to open file ($filename)");
根据那里的功能,我认为没有任何区别,因为两者都会终止脚本的执行。
我的问题是
1) 在这些示例中,我可以将 die 与 exit 互换,反之亦然吗?
2) 还有这些的区别。
干杯...
【问题讨论】:
-
正如@AdamPlocher 所说,它们是一回事。使用你最喜欢的女巫。
-
我实际上只看到它们以其他方式使用......“或死(..)”等 :) 但就像说的那样,没有区别
-
mysql函数将被弃用,请使用PDO或mysqli;