PHP Error: “Call to member function create() on a non-object” Twilio code [closed]

别来无恙 提交于 2019-12-13 04:21:15

问题


I'm trying to get a version of Twilio-PHP code working. I've hosted it and the Twilio library here.

An error is thrown on this line:

$response = $client->account->sms_messages->create($from,$number,$text);

It throws the error:

"Call to member function create() on a non-object"

I define $from, $number, and $text above as strings. The first two are verified Twilio $text="Hi";. The syntax of the call is cut and paste from the Quickstart section of that GitHub and so it is more likely that I am not using the code properly.

There wasn't enough explanation in this question for me to understand the error message.


Actual Code

  <?php
 require './twilio-php/Services/Twilio.php';

 $AccountSid = X;
 $AuthToken =X;

 $client = new Services_Twilio($AccountSid,$AuthToken);
 $number = "1111";
 $text = "This is a test";
 $from = "2222";
 $response = $client->account->sms_smessages->create($from,$number,$text);
 ?>

Note: I replaced the real numbers and authorization tokens with dummies.


回答1:


I don't know how your application works in detail and why it is not an object, but you should add a check:

if(!is_object($client->account->sms_messages)) {
    var_dump($client);
    die('something bad happened');
}

...



回答2:


$response = $client->account->sms_messages->create($from,$number,$text);

You had a typo in sms_messages



来源:https://stackoverflow.com/questions/16936886/php-error-call-to-member-function-create-on-a-non-object-twilio-code

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!