久久久久久久视色,久久电影免费精品,中文亚洲欧美乱码在线观看,在线免费播放AV片

<center id="vfaef"><input id="vfaef"><table id="vfaef"></table></input></center>

    <p id="vfaef"><kbd id="vfaef"></kbd></p>

    
    
    <pre id="vfaef"><u id="vfaef"></u></pre>

      <thead id="vfaef"><input id="vfaef"></input></thead>

    1. 站長(zhǎng)資訊網(wǎng)
      最全最豐富的資訊網(wǎng)站

      詳解PHP如何才能更好的利用PHPstorm的自動(dòng)提示

      詳解PHP如何才能更好的利用PHPstorm的自動(dòng)提示

      寫(xiě)了一段時(shí)間的java之后,特別不習(xí)慣PHP本身的弱類型方式,在寫(xiě)代碼的時(shí)候總覺(jué)得不怎么放心,特別本身PHP又是弱類型的語(yǔ)言,所以在編碼的時(shí)候,很多時(shí)候是沒(méi)有代碼提示的。

      一個(gè)一般例子 (推薦學(xué)習(xí):phpstorm詳解)

      class Data {   public $name;   public $gender;   public $age;   public function __construct($name,$gender,$age) {     $this->name = $name;     $this->gender = $gender;     $this->age = $age;   } } class Test {   public function run() {     $data = [       new Data('張三','男',18),       new Data('李四','男',14),       new Data('王五','男',17),       new Data('大姨媽','女',23),     ];   }   private function eachData($data) {     foreach($data as $item) {       echo $item->name.'=>'.$item->gender.'=>'.$item->age."n";     }   } } (new Test)->run();

      以上例子來(lái)看,一般來(lái)說(shuō)其實(shí)也是不存在什么問(wèn)題的,但是在編寫(xiě)

      cho $item->name.'=>'.$item->sex.'=>'.$item->age."n";

      這段代碼的時(shí)候,在調(diào)用屬性的時(shí)候是沒(méi)有自動(dòng)提示的,那么數(shù)據(jù)量大的時(shí)候需要往上翻然后進(jìn)行copy或者編寫(xiě)下來(lái),降低編碼速度,而且有時(shí)候心里還沒(méi)譜,怕寫(xiě)錯(cuò)。

      以下是我寫(xiě)的一個(gè)完整的利用注釋和本身PHP特性的例子:

      class Data {   public $name;   public $gender;   public $age;   public function __construct($name,$gender,$age) {     $this->name = $name;     $this->sex = $gender;     $this->age = $age;   } } class Test {   public function run() {     $data = [       new Data('張三','男',18),       new Data('李四','男',14),       new Data('王五','男',17),       new Data('大姨媽','女',23),     ];   }   /**    * 遍歷輸出數(shù)據(jù)    * @param array $data    */   private function eachData($data) {     foreach($data as $item) {       if($item instanceof Data) {         echo $item->name.'=>'.$item->gender.'=>'.$item->age."n";       }     }   } } (new Test)->run();

      這里主要的是加了一個(gè)if判斷,判斷數(shù)據(jù)類型是否是Data的一個(gè)具體實(shí)例;

      在這個(gè)地方,PHPstorm會(huì)根據(jù)這個(gè)判斷在做$item屬性調(diào)用的時(shí)候會(huì)有自動(dòng)提示,非常的方便。

      思考

      從這里得到的一些思考,那就是我們?cè)诰帉?xiě)程序的時(shí)候可以更好的考慮嚴(yán)謹(jǐn)性,從上面的例子來(lái)看,這樣子做了,再加一些錯(cuò)誤處理機(jī)制,能更好的保證數(shù)據(jù)的安全性和完整性,不僅僅是編輯器提示的方便。

      后續(xù)再做代碼檢查和跟蹤的時(shí)候,將也是一件非常方便的事情,而且業(yè)務(wù)邏輯也更清晰。

      贊(0)
      分享到: 更多 (0)
      網(wǎng)站地圖   滬ICP備18035694號(hào)-2    滬公網(wǎng)安備31011702889846號(hào)