$errno
错误号,为 0 时,表示正常,非 0 时表示错误。
在某些函数被调用后发生错误,该全局变量会被设置,有点类似于 Linux C 的 errno 。
因为 PHP 是同步的(区别于异步)并且线程安全的,所以使用这种方法来返回错误会很方便。
一般配合 errstr 一起使用,函数内通过 xn_error($errno, $errstr) 设置错误。
相比起抛出异常来,这种处理方式会轻量级很多。
【定义】 文件:xiunophp/xiunophp.php 大约 58 行:
$errno = 0;
【用例】
<?php
include "./xiunophp/xiunophp.php";
include "./xiunophp/xn_send_mail.php";
$r = xn_send_mail(array(), "username", "test@gmail.com", "标题", "内容");
if($r === FALSE) {
echo "Errno:".$errno.", Errstr:".$errstr;
}
?>
【相关函数】
xn_error()