您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息
三六零分类信息网 > 丹东分类信息网,免费分类信息发布

静态变量/方法问题

2025/10/29 3:55:24发布53次查看
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) {}
丹东分类信息网,免费分类信息发布

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product