[英]Why would this line of code be executed if the IF condition is false? Doesn't make any sense
这是代码:
<?php
class Order extends Zend_Db_Table_Abstract
{
protected $_name = 'orders';
protected $_limit = 200;
protected $_authorised = false;
public function setLimit($limit)
{
$this->_limit = $limit;
}
public function setAuthorised($auth)
{
$this->_authorised = (bool) $auth;
}
public function insert(array $data)
{
if ($data['amount'] > $this->_limit && $this->_authorised === false) {
throw new Exception('Unauthorised transaction of greater than ' . this->_limit . ' units');
}
return parent::insert($data);
}
}
如果条件失败,为什么只运行该方法。 我是C#程序员,我的逻辑表明无论IF如何它都会运行,对吗? 太感谢了。
异常将中断代码执行。
即使在C#中,即使抛出异常,也不会执行代码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.