Azure / azure-storage-php

Microsoft Azure Storage Library for PHP
MIT License
217 stars 197 forks source link

Error PHP8.1 Azure Storage #347

Open nlardev-hublot opened 1 year ago

nlardev-hublot commented 1 year ago

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 https://github.com/Azure/azure-storage-common-php/issues/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.)

andychoi commented 3 months ago

Please help fix this problem.

PHP Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /var/www/wordpress/wp-content/plugins/windows-azure-storage/vendor/microsoft/azure-storage-blob/src/Blob/Models/CopyState.php on line 77

Environment: Azure web app / Wordpress container provided by Microsoft PHP 8.2.15 (cli) (built: Jan 27 2024 04:53:38) (NTS)