php如何输入错误返回,php – 从函数返回“错误”的最佳做法

我有一个功能:

public function CustomerRating() {

$result = $db->query("...");

$row = $result->fetch_assoc();

if($row)

$output = $row['somefield'];

} else {

$output = "error";

}

return $output;

}

//somewhere on another page...

if(is_numeric($class->CustomerRating()) {

echo $class->CustomerRating;

} else {

echo "There is an error with this rating.";

}

有没有更好的方法来发现错误?在这个函数中,如果没有返回任何行,它本身并不意味着“错误”,它只是意味着无法计算该值.当我检查一个函数的结果时,我觉得有一个更好的方法来检查在if函数中显示之前返回的数据.最好的方式是做什么?我想返回一个“false”,但是当调用这个函数时我该怎么检查呢?谢谢!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值