Static variable/method problem

Source: Internet
Author: 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 ' = ' Invalid parameters ');            Break } $url = self:: $ms _conf[' url '].    Method= '. $method;            } while (0);    return $url; /** * Send verification code SMS * @param [type] $mobile phone number * @param array $param captcha:array (' Code ' = ' mi Nute ' + ') * @return Array Callback information */public static function Send ($mobile = ', $param = Array ()) {        do{if (! $mobile) {$result = array (' status ' = ' failed ', ' results ' = ' = ')                Missing [Mobile] parameter ');            Break } if (!isset ($param [' Code ')]) {$result = array (' status ' = ' failed ', '                Results ' = ' and ' ERROR ' [code] parameter ');            Break } $param _arr = Array (' mobile ' = $mobile, ' content ' = ' @1@={$param [ ' Code '} ', ' sendtime ' + ', ' msgtype ' = 2, ' tempid ' and ' J '            sm40485-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 ' = ' = ' + ') ', ' Commit '                = $back _result[1])); }//else//{//$msg = Self::senderror ($back _res                ULT);                $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

No systematic reading of the book, Solving!!!

Reply content:

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 ' = ' Invalid parameters ');            Break } $url = self:: $ms _conf[' url '].    Method= '. $method;            } while (0);    return $url; /** * Send verification code SMS * @param [type] $mobile phone number * @param array $param captcha:array (' Code ' = ' mi Nute ' + ') * @return Array Callback information */public static function Send ($mobile = ', $param = Array ()) {        do{if (! $mobile) {$result = array (' status ' = ' failed ', ' results ' = ' = ')                Missing [Mobile] parameter ');            Break } if (!isset ($param [' Code ')]) {$result = array (' status ' = ' failed ', '                Results ' = ' and ' ERROR ' [code] parameter ');            Break } $param _arr = Array (' mobile ' = $mobile, ' content ' = ' @1@={$param [ ' Code '} ', ' sendtime ' + ', ' msgtype ' = 2, ' tempid ' and ' J '            sm40485-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 ' = ' = ' + ') ', ' Commit '                = $back _result[1])); }//else//{//$msg = Self::senderror ($back _res                ULT);                $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

No systematic reading of the book, Solving!!!

May I ask how you call that?
That static method of yours is private , how do you call this method?

When a static method is called, the constructor of the class is not automatically called.
So your $ms_conf is an empty array, so you should know the result?


  
   

执行结果:

tttarray(0) {}
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    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.