IF koşulu yanlış ise neden bu kod satırı idam olurdu?

3 Cevap php

İşte kod:

<?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);
 }
 }

Neden durum bu yöntem koşmak ONLY başarısız olsaydı. Ben bir C # programcısı değilim, benim mantık doğru olursa olsun IF çalışacağını belirler? Bir milyon teşekkürler.

3 Cevap

Eğer bir istisna, o genellikle bir try...catch deyimi yoksa kalan kod çıkmak neden olur. Miktarı 200 daha büyüktür ve kullanıcı yetkili değilse Böylece, bu if deyimi içinde bloğunu çalıştırır.

Eğer sağlanan bağlantı bahseder o will be caught. Since it's not caught in your code above (the model), execution inside of the model stops and is passed up the stack to the controller. It does not return to your model, thus the line following the if denilen olmayacak bir kontrolöre "kadar kabarcık" olacak.

Daha fazla bilgi için PHP manual on exceptions göz atın.

İstisna kod yürütülmesine kesecektir.

Bir istisna ötesinde kodu atılır bile C # idam almaz.