salesforce-marketingcloud / FuelSDK-PHP

FuelSDK-PHP
MIT License
134 stars 142 forks source link

[undefined array index in ET_Client.php in function getAuthTokenExpiration if $tenantKey and $this->tenantTokens are null] #168

Open rizhk opened 2 years ago

rizhk commented 2 years ago

Describe the bug undefined array index in ET_Client.php in function getAuthTokenExpiration if $tenantKey and $this->tenantTokens

To Reproduce use php 7.4 and try to send email

Expected behavior It is doing nothing, because undefined array index in php 7.4

Screenshots If applicable, add screenshots to help explain your problem.

Code snippet function getAuthTokenExpiration($tenantKey) { $tenantKey = $tenantKey == null ? $this->tenantKey : $tenantKey;

              /* please check $tenantKey is already null*/
              /*if ($tenantKey  && $this->tenantTokens[$tenantKey] == null)  */

    if ($this->tenantTokens[$tenantKey] == null) {
        $this->tenantTokens[$tenantKey] = array();
    }
    return isset($this->tenantTokens[$tenantKey]['authTokenExpiration'])
        ? $this->tenantTokens[$tenantKey]['authTokenExpiration']
        : null;
}

Note: Because the developers need to copy and paste the code snippet, including a code snippet as a media file (e.g. gif) is not sufficient.

Environment

The bug has the severity

garek007 commented 1 year ago

Any fix for this? For me, this isn't shutting me down entirely, as I can still make other calls, but it is causing difficulties when integrating with Symfony.

garek007 commented 1 year ago

Looks like this may fix it for me, but not sure if doing it this way will have other downstream impacts.

if (!isset($this->tenantTokens[$tenantKey])) {

rizhk commented 1 year ago

Great Garek, i will add it to the code. Thank you

garek007 commented 1 year ago

Sorry I mean that I edited my own. I just noticed that you submitted a fix and wanted it merged. I'm unable to merge in this repo.

rizhk commented 1 year ago

Ok i will merge it, thank you

jusmark123 commented 1 year ago

What is the status of this? This makes the code unusable. Is there a workaround? This is quite an old request, so I'm a bit surprised this hasn't been fixed. How do I set the tenant key? The tenantTokens property is never initialized as an array, yet it is assumed to be an array. Even if tenantTokens is initialized as an array, if tenantKey is null, it cannot be used as an array key. This is a pretty glaring problem and should be corrected ASAP.

rizhk commented 1 year ago

hey @jusmark123 could you please use this https://github.com/rizhk/FuelSDK-PHP/commits/v1.7.0 ? let me know if that works for you :)

jusmark123 commented 1 year ago

Will try thanks