0

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.

Community
  • 1
  • 1
mac389
  • 3,004
  • 5
  • 38
  • 62

2 Answers2

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');
}

...
hek2mgl
  • 152,036
  • 28
  • 249
  • 266
  • 2
    I know it's just a little hint, and the question might be deleted once anyway, but why the down-vote? – hek2mgl Jun 05 '13 at 10:08
  • Agree- I'm not experienced in PHP and asking a genuine question after searching Twilios FAQs and SO without finding an answer I could understand that was helpful. – mac389 Jun 05 '13 at 10:10
  • I upvoted your answer to make you feel a bit better :) – Matheno Jun 05 '13 at 10:13
  • @mac389 I expect, that the `$client` object has not property `sms_messages` if the there are no messages. So you can use me check above to detect that – hek2mgl Jun 05 '13 at 10:17
1
$response = $client->account->sms_messages->create($from,$number,$text);

You had a typo in sms_messages

Matheno
  • 4,112
  • 6
  • 36
  • 53