如何在 PHP 中调试 "Call to a member function X on null"?
How to debug "Call to a member function X on null" in PHP?
我被 php CMS 中的错误卡住了:
PHP Fatal error: Call to a member function send_sms() on null in /home/zleepcom/public_html/view/CartView.php on line 117
这是调用方法的代码:
$this->notify->sms_send($order->phone,'Ваш заказ №'.$order->id.' принят. На сумму '.$order->total_price.' '.$this->currency->sign.'. Спасибо за заказ!');
这是函数:
public function send_sms($r,$m)
{
public $sender='xxx';
public $slogin='xxx';
public $spwd='xxx';
public $pdo;
try{
$pdo = new PDO ("mysql:host=77.120.116.10;dbname=users",$slogin,$spwd);
$pdo->query("SET NAMES utf8;");
$pdo->query("INSERT INTO `{$slogin}` (`number`,`message`,`sign`) VALUES ('$r','$m','$sender')");
}catch(Exception $e){
$client = new SoapClient ('http://turbosms.in.ua/api/wsdl.html');
$auth = array(
'login' => $slogin,
'password' => $spwd
);
$res=$client->Auth($auth);
$sms = array(
'sender' => $sender,
'destination' => $r,
'text' => $m
);
$res=$client->SendSMS($sms);
}
}
如有任何帮助,我将不胜感激
错误的意思是$this->notify
是null
。您发布的内容还不足以让我们说 为什么 它是 null
(它必须在您之前的代码中),但这是您的问题。
我被 php CMS 中的错误卡住了:
PHP Fatal error: Call to a member function send_sms() on null in /home/zleepcom/public_html/view/CartView.php on line 117
这是调用方法的代码:
$this->notify->sms_send($order->phone,'Ваш заказ №'.$order->id.' принят. На сумму '.$order->total_price.' '.$this->currency->sign.'. Спасибо за заказ!');
这是函数:
public function send_sms($r,$m)
{
public $sender='xxx';
public $slogin='xxx';
public $spwd='xxx';
public $pdo;
try{
$pdo = new PDO ("mysql:host=77.120.116.10;dbname=users",$slogin,$spwd);
$pdo->query("SET NAMES utf8;");
$pdo->query("INSERT INTO `{$slogin}` (`number`,`message`,`sign`) VALUES ('$r','$m','$sender')");
}catch(Exception $e){
$client = new SoapClient ('http://turbosms.in.ua/api/wsdl.html');
$auth = array(
'login' => $slogin,
'password' => $spwd
);
$res=$client->Auth($auth);
$sms = array(
'sender' => $sender,
'destination' => $r,
'text' => $m
);
$res=$client->SendSMS($sms);
}
}
如有任何帮助,我将不胜感激
错误的意思是$this->notify
是null
。您发布的内容还不足以让我们说 为什么 它是 null
(它必须在您之前的代码中),但这是您的问题。