Expectation: A call will go through from your Twilio number to the provided phone number.
Actual behavior: An exception is thrown.
[Wed Sep 15 13:43:03 2021] PHP Fatal error: Uncaught Twilio\Exceptions\ConfigurationException: Credentials are required to create a Client in /Users/mmenschig/Projects/dev/php/clicktocall-php/vendor/twilio/sdk/src/Twilio/Rest/Client.php:170
Stack trace:
#0 /Users/mmenschig/Projects/dev/php/clicktocall-php/src/call.php(36): Twilio\Rest\Client->__construct('', '')
#1 {main}
thrown in /Users/mmenschig/Projects/dev/php/clicktocall-php/vendor/twilio/sdk/src/Twilio/Rest/Client.php on line 170
[Wed Sep 15 13:43:03 2021] [::1]:60740 [200]: POST /call.php - Uncaught Twilio\Exceptions\ConfigurationException: Credentials are required to create a Client in /Users/mmenschig/Projects/dev/php/clicktocall-php/vendor/twilio/sdk/src/Twilio/Rest/Client.php:170
Stack trace:
#0 /Users/mmenschig/Projects/dev/php/clicktocall-php/src/call.php(36): Twilio\Rest\Client->__construct('', '')
#1 {main}
thrown in /Users/mmenschig/Projects/dev/php/clicktocall-php/vendor/twilio/sdk/src/Twilio/Rest/Client.php on line 170
[Wed Sep 15 13:43:03 2021] [::1]:60740 Closing
Version of PHP:
Composer.json modification (I've added PHP ^8.0 as a supported version)
Expectation: A call will go through from your Twilio number to the provided phone number.
Actual behavior: An exception is thrown.
The issue appears to stem from the following lines in call.php: Link: https://github.com/TwilioDevEd/clicktocall-php/blob/15d16f2ecef9624b1aa74f35ada525f9d86100cb/src/call.php#L30-L33
Note that both
getenv()
andputenv()
are not thread safe and their usage is strongly discouraged: https://github.com/vlucas/phpdotenv#putenv-and-getenvOne workaround is to access the
$_ENV
object instead:NB: The same workaround needs to be applied to retrieving the $TWILIO_NUMBER as well:
$TWILIO_NUMBER = $_ENV['TWILIO_NUMBER'];
Once these changes are applied the application works as expected.