靜態變數/方法問題

來源:互聯網
上載者:User
class Common_Sms{    protected static $ms_conf = array();     public function __construct(){        self::$ms_conf = array(            'url'        => '1212',            'username'    => 'XXX',            'password'    => 'OOO',            'veryCode'    => 'KKK'        );     }        private static function curl_post($method = '', $param = array()) {        do {            if(! $method || empty($param)) {                $ret = array(                        'status' => 'failed',                        'msg'     => 'Invalid param',                        'results'=> '無效的參數'                    );                break;            }            $url = self::$ms_conf['url'] .'?method='.$method;    } while(0);            return $url;    }        /**     * 發送驗證碼簡訊     * @param  [type] $mobile 手機號     * @param  array  $param  captcha: array( 'code'=> , 'minute' => )     * @return array         回傳資訊     */    public static function send($mobile = '', $param = array()){        do{            if(!$mobile)            {                $result = array('status' => 'failed', 'results' => '缺少[mobile] 參數');                break;            }                        if(!isset($param['code']))            {                $result = array('status' => 'failed', 'results' => '錯誤的[code] 參數');                break;            }            $param_arr = array(                'mobile'    => $mobile,                'content'    => "@1@={$param['code']}",                'sendtime'    => '',                'msgtype'    => 2,                'tempid'    => 'JSM40485-0001',                'code'        => 'utf-8',                );            $req_result = self::curl_post('sendMsg', $param_arr);            if($req_result['status'] == 'success')            {                // $req_result = trim($req_result);                                // $back_result = explode('#', $req_result);                // if($back_result[0] == 0)                // {                //     $result = array('status' => 'success', 'results' => array('send' => $back_result[2], 'commit' => $back_result[1]));                // }                // else                // {                                    //     $msg = self::sendError($back_result);                //     $result = array('status' => 'failed', 'results' => $msg);                // }                    //                                 return $req_result['results'];                            }            else            {                $result = array('status' => 'failed', 'results' => $req_result['msg']);                break;            }                    } while(0);        return $result;    }}

A PHP Error was encountered
Severity: Notice
Message: Undefined index: url
Filename: common/sms.php
Line Number: 32

沒有系統的看過書,求解 !!!

回複內容:

class Common_Sms{    protected static $ms_conf = array();     public function __construct(){        self::$ms_conf = array(            'url'        => '1212',            'username'    => 'XXX',            'password'    => 'OOO',            'veryCode'    => 'KKK'        );     }        private static function curl_post($method = '', $param = array()) {        do {            if(! $method || empty($param)) {                $ret = array(                        'status' => 'failed',                        'msg'     => 'Invalid param',                        'results'=> '無效的參數'                    );                break;            }            $url = self::$ms_conf['url'] .'?method='.$method;    } while(0);            return $url;    }        /**     * 發送驗證碼簡訊     * @param  [type] $mobile 手機號     * @param  array  $param  captcha: array( 'code'=> , 'minute' => )     * @return array         回傳資訊     */    public static function send($mobile = '', $param = array()){        do{            if(!$mobile)            {                $result = array('status' => 'failed', 'results' => '缺少[mobile] 參數');                break;            }                        if(!isset($param['code']))            {                $result = array('status' => 'failed', 'results' => '錯誤的[code] 參數');                break;            }            $param_arr = array(                'mobile'    => $mobile,                'content'    => "@1@={$param['code']}",                'sendtime'    => '',                'msgtype'    => 2,                'tempid'    => 'JSM40485-0001',                'code'        => 'utf-8',                );            $req_result = self::curl_post('sendMsg', $param_arr);            if($req_result['status'] == 'success')            {                // $req_result = trim($req_result);                                // $back_result = explode('#', $req_result);                // if($back_result[0] == 0)                // {                //     $result = array('status' => 'success', 'results' => array('send' => $back_result[2], 'commit' => $back_result[1]));                // }                // else                // {                                    //     $msg = self::sendError($back_result);                //     $result = array('status' => 'failed', 'results' => $msg);                // }                    //                                 return $req_result['results'];                            }            else            {                $result = array('status' => 'failed', 'results' => $req_result['msg']);                break;            }                    } while(0);        return $result;    }}

A PHP Error was encountered
Severity: Notice
Message: Undefined index: url
Filename: common/sms.php
Line Number: 32

沒有系統的看過書,求解 !!!

請問你怎麼調用的?
你的那個 靜態方法 是 private 的, 你怎麼調用的這個方法?

靜態方法在調用的時候, 類的建構函式是不會被自動調用的.
所以你的 $ms_conf 是一個空數組, 所以結果你應該懂的吧?

執行結果:

tttarray(0) {}
  • 相關文章

    聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.