问题
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