Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHP Fatal error: Cannot redeclare Services_Twilio_autoload() #218

Closed
piavgh opened this issue Mar 26, 2015 · 2 comments
Closed

PHP Fatal error: Cannot redeclare Services_Twilio_autoload() #218

piavgh opened this issue Mar 26, 2015 · 2 comments

Comments

@piavgh
Copy link

piavgh commented Mar 26, 2015

Hi everyone,

I use Phalcon PHP framework to make my web api. I use base project here https://github.com/jeteokeeffe/php-hmac-rest-api

Now I need to use Twilio for SMS.

I put twilio-php folder in library folder and then I included it in index.php

require $appDir . '/library/twilio-php/Services/Twilio.php';

But I got this error

"PHP Fatal error:  Cannot redeclare Services_Twilio_autoload() (previously declared in /usr/share/nginx/html/2way/api/app/library/twilio-php/Services/Twilio.php:9) in /usr/share/nginx/html/2way/api/app/library/twilio-php/Services/Twilio.php on line 9"

I checked this Twilio.php file and I tried to

var_dump(dirname(__FILE__) . "/Twilio.php"); die;

before this line

return include dirname(__FILE__) . "/Twilio.php";

The return value is

string(73) "/usr/share/nginx/html/2way/api/app/library/twilio-php/Services/Twilio.php"

Which is the same file (Twilio.php)

Is this why I got the "Cannot redeclare Services_Twilio_autoload()" error?
How to solve this?

Thank you very much

@ecaron
Copy link

ecaron commented Apr 9, 2015

There are two options:

  • The immediate cheap-and-dirty would be changing all your require and include to require_once and include_once
  • Don't include Twilio directly, but instead put it in the composer.json file and rely on the composer autoloader to provide the class whenever you need it.

You also might find more appropriate assistance at the Twilio tag on StackOverflow

@piavgh
Copy link
Author

piavgh commented Apr 9, 2015

Hi eracon,

Your first solution doesn't work, I tried that before posting this issue :)

But I am able to make it work now by making a single Twilio.php file that contain every class needed for SMS. This is maybe the dirtiest way but it works.

I wll close this issue now

@piavgh piavgh closed this as completed Apr 9, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants