国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

PHP鏈?zhǔn)秸{(diào)用如何在中間返回信息
學(xué)習(xí)ing
學(xué)習(xí)ing 2017-07-05 10:46:11
0
3
1181

PHP鏈?zhǔn)秸{(diào)用如何在中間錯(cuò)誤的時(shí)候拿到錯(cuò)誤信息

這里的錯(cuò)誤信息不是簡(jiǎn)單的字符串,比如鏈?zhǔn)秸{(diào)用過(guò)程中可能某一個(gè)函數(shù)在不滿足某個(gè)條件的時(shí)候,需要返回一個(gè)數(shù)組,直接報(bào)錯(cuò),說(shuō)數(shù)組無(wú)法調(diào)用下一個(gè)函數(shù),但是如何能做到在中間某個(gè)函數(shù)返回的條件下不再往后繼續(xù)調(diào)用呢?

學(xué)習(xí)ing
學(xué)習(xí)ing

全部回復(fù)(3)
世界只因有你

嘗試捕捉

習(xí)慣沉默

是不是下面的這個(gè)樣子呢?

<?php

class Demo
{
    protected $result;
    protected $error = false;
    
    function funcA() 
    {
        if (! $this->error) {
            //do xxx
        }
        
        return $this;
    }
    
    function funcB() 
    {
        if (! $this->error) {
            //do xxx
            //模擬發(fā)生錯(cuò)誤
            $this->error = true;
            $this->result = ['Ops!', 'Something bad Happened!'];
        }
        
        return $this;
    }
    
    function funcC() 
    {
        if (! $this->error) {
            //do xxx
        }
        
        return $this;
    }
    
    function GetResult() {
        return [$this->result, $this->error];
    }
}

$demo = new Demo();

list($result, $hasError) = $demo->funcA()->funcB()->funcC()->GetResult();

var_dump($result, $hasError);

PS: 感覺(jué)寫(xiě)出了 golang 的感覺(jué)

在線把玩 https://glot.io/snippets/ereygerdv3

小葫蘆

throw new Exception('error');

最新下載
更多>
網(wǎng)站特效
網(wǎng)站源碼
網(wǎng)站素材
前端模板