Skip to content
This repository was archived by the owner on May 8, 2024. It is now read-only.
This repository was archived by the owner on May 8, 2024. It is now read-only.

Error PHP8.1 Azure Storage #347

@nlardev-hublot

Description

@nlardev-hublot

Which service(blob, file, queue, table) does this issue concern?

Blob Storage

Which version of the SDK was used?

"microsoft/azure-storage-blob": "^1.5"

What's the PHP/OS version?

PHP 8.1.6

What problem was encountered?

Deprecated: substr(): Passing null to parameter Azure/azure-storage-common-php#1 ($string) of type string is deprecated in /DIR_APP/vendor/microsoft/azure-storage-common/src/Common/Internal/Utilities.php on line 615

Steps to reproduce the issue?

Using version of PHP 8.0 or greater, try to create:

$connectionString = sprintf('BlobEndpoint=https://%s.blob.core.windows.net;SharedAccessSignature=%s', $storageAccount, $sasToken);
$blobClient       = BlobRestProxy::createBlobService($connectionString);

We are able to pass only BlobEndpoint, but we are not able to pass secondary Endpoing. Then in:
app/code/Hublot/CryptoPayment/Model/Blob/BlobRestProxy.php
$secondaryUri = Utilities::tryAddUrlScheme( $settings->getBlobSecondaryEndpointUri() );
$secondaryUri will be null.
and then in:
vendor/microsoft/azure-storage-common/src/Common/Internal/Utilities.php:603

public static function endsWith($haystack, $needle, $ignoreCase = false)
    {
        if ($ignoreCase) {
            $haystack = strtolower($haystack);
            $needle   = strtolower($needle);
        }
        $length = strlen($needle);
        if ($length == 0) {
            return true;
        }

        return (substr($haystack, -$length) === $needle);
    }

haystack will be null, which will throw exception in php 8.0 or greater version, it should be string.

Have you found a mitigation/solution?

Yes.

One of the option to fix the issue is to be able to change:
vendor/microsoft/azure-storage-common/src/Common/Internal/StorageServiceSettings.php:189
$blobSecondaryEndpointUri = null, to $blobSecondaryEndpointUri = '', or to be able to set $blobSecondaryEndpointUri thry setter.

Other solution is:
app/code/Hublot/CryptoPayment/Model/Blob/BlobRestProxy.php:142

        $secondaryUri = Utilities::tryAddUrlScheme(
            $settings->getBlobSecondaryEndpointUri()
        ) ?: '';

Is there a failing request ID related to this problem returned by server? What is it?

No

What is the storage account name and time frame of your last reproduce? (UTC YYYY/MM/DD hh:mm:ss)

I am not able to provide that information.

(If you think some of the information should not be shared publicly, you can e-mail the main Microsoft contributors of the repository instead.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions