Skip to content
This repository has been archived by the owner on Jul 27, 2023. It is now read-only.

parseFrom(NULL) error #2

Open
plash29 opened this issue Jan 18, 2018 · 4 comments
Open

parseFrom(NULL) error #2

plash29 opened this issue Jan 18, 2018 · 4 comments

Comments

@plash29
Copy link

plash29 commented Jan 18, 2018

Exception 'TypeError' with message 'Argument 1 passed to dosamigos\twilio\TwilioComponent::parseFrom() must be of the type string, null given, called in E:\wamp64\www\GigsHero\vendor\2amigos\yii2-twilio-component\src\TwilioComponent.php on line 69' 

in E:\wamp64\www\GigsHero\vendor\2amigos\yii2-twilio-component\src\TwilioComponent.php:114

Stack trace:
#0 E:\wamp64\www\GigsHero\vendor\2amigos\yii2-twilio-component\src\TwilioComponent.php(69): dosamigos\twilio\TwilioComponent->parseFrom(NULL)
#1 E:\wamp64\www\GigsHero\controllers\RegistrationController.php(108): dosamigos\twilio\TwilioComponent->sms('9501045616', 'Hello World!')
#2 [internal function]: app\controllers\RegistrationController->actionCustomer()
#3 E:\wamp64\www\GigsHero\vendor\yiisoft\yii2\base\InlineAction.php(57): call_user_func_array(Array, Array)
#4 E:\wamp64\www\GigsHero\vendor\yiisoft\yii2\base\Controller.php(157): yii\base\InlineAction->runWithParams(Array)
#5 E:\wamp64\www\GigsHero\vendor\yiisoft\yii2\base\Module.php(528): yii\base\Controller->runAction('customer', Array)
#6 E:\wamp64\www\GigsHero\vendor\yiisoft\yii2\web\Application.php(103): yii\base\Module->runAction('registration/cu...', Array)
#7 E:\wamp64\www\GigsHero\vendor\yiisoft\yii2\base\Application.php(386): yii\web\Application->handleRequest(Object(yii\web\Request))
#8 E:\wamp64\www\GigsHero\web\index.php(17): yii\base\Application->run()
#9 {main}
@stevekr
Copy link

stevekr commented Oct 18, 2018

Getting the same error

@Aksi0
Copy link

Aksi0 commented May 7, 2019

Getting the same

@kublermdk
Copy link

Any resolution on this? I'm also having the same issue.

'twilio' => [
    'class' => '\dosamigos\twilio\TwilioComponent', // Based off https://github.com/2amigos/yii2-twilio-component
    'sid' => 'ACd34ca65b....', 
    'token' => '895709be8...',
    'phoneNumber' => '+15005550006' // Test phone number https://www.twilio.com/docs/iam/test-credentials
]

It looks like the phoneNumber isn't being picked up. But I've tried different numbers, including the example test ones that should always be valid and it's not working. The error occurs when running the the Yii::$app->twilio->sms($user->mobile, $messageContents); method.

Looks like it could be because I'm not specifying the from in the call?

If I do, then it works. e.g

Yii::$app->twilio->sms($user->mobile, $messageContents, ['from' => '+15005550006']);

Simply removing the string qualifier from vendor/2amigos/yii2-twilio-component/src/TwilioComponent.php:114 also fixes the issue.
e.g:
protected function parseFrom($from): string

As it looks like null should be allowed as well as a string.

@Eseperio
Copy link

Eseperio commented Oct 23, 2019

Since PHP 7.1 you can set the property optional prepending a question sign

    protected function parseFrom(?string $from): string

https://wiki.php.net/rfc/nullable-casting

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants