Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHP 8.4 deprecation "Implicitly marking parameter as nullable" #835

Open
adrianbj opened this issue Dec 18, 2024 · 6 comments
Open

PHP 8.4 deprecation "Implicitly marking parameter as nullable" #835

adrianbj opened this issue Dec 18, 2024 · 6 comments

Comments

@adrianbj
Copy link

Issue Summary

There are several instances of this deprecation warning. Given that you still want to support PHP 7.2, the solution is to use the question mark solution rather than union types (which aren't supported until PHP 8).

eg:

interface Client {
    public function request(string $method, string $url,
                            array $params = [], array $data = [], array $headers = [],
                            ?string $user = null, ?string $password = null,
                            ?int $timeout = null): Response;
} 

Steps to Reproduce

  1. Use the library on PHP 8.4

Exception/Log

PHP Deprecated: Twilio\Base\BaseClient::__construct(): Implicitly marking parameter $username as nullable is deprecated, the explicit nullable type must be used instead in twilio/sdk/src/Twilio/Base/BaseClient.php:51 
PHP Deprecated: Twilio\Base\BaseClient::__construct(): Implicitly marking parameter $password as nullable is deprecated, the explicit nullable type must be used instead in twilio/sdk/src/Twilio/Base/BaseClient.php:0 
PHP Deprecated: Twilio\Base\BaseClient::__construct(): Implicitly marking parameter $accountSid as nullable is deprecated, the explicit nullable type must be used instead in twilio/sdk/src/Twilio/Base/BaseClient.php:0 
PHP Deprecated: Twilio\Base\BaseClient::__construct(): Implicitly marking parameter $region as nullable is deprecated, the explicit nullable type must be used instead in twilio/sdk/src/Twilio/Base/BaseClient.php:0 
PHP Deprecated: Twilio\Base\BaseClient::__construct(): Implicitly marking parameter $httpClient as nullable is deprecated, the explicit nullable type must be used instead in twilio/sdk/src/Twilio/Base/BaseClient.php:0 
PHP Deprecated: Twilio\Base\BaseClient::__construct(): Implicitly marking parameter $environment as nullable is deprecated, the explicit nullable type must be used instead in twilio/sdk/src/Twilio/Base/BaseClient.php:0 
PHP Deprecated: Twilio\Base\BaseClient::__construct(): Implicitly marking parameter $userAgentExtensions as nullable is deprecated, the explicit nullable type must be used instead in twilio/sdk/src/Twilio/Base/BaseClient.php:0 
PHP Deprecated: Twilio\Base\BaseClient::request(): Implicitly marking parameter $username as nullable is deprecated, the explicit nullable type must be used instead in twilio/sdk/src/Twilio/Base/BaseClient.php:116 
PHP Deprecated: Twilio\Base\BaseClient::request(): Implicitly marking parameter $password as nullable is deprecated, the explicit nullable type must be used instead in twilio/sdk/src/Twilio/Base/BaseClient.php:116 
PHP Deprecated: Twilio\Base\BaseClient::request(): Implicitly marking parameter $timeout as nullable is deprecated, the explicit nullable type must be used instead in twilio/sdk/src/Twilio/Base/BaseClient.php:116 
PHP Deprecated: Twilio\Base\BaseClient::setEdge(): Implicitly marking parameter $edge as nullable is deprecated, the explicit nullable type must be used instead in twilio/sdk/src/Twilio/Base/BaseClient.php:344 
PHP Deprecated: Twilio\Base\BaseClient::setLogLevel(): Implicitly marking parameter $logLevel as nullable is deprecated, the explicit nullable type must be used instead in twilio/sdk/src/Twilio/Base/BaseClient.php:384 
PHP Deprecated: Twilio\Http\CurlClient::request(): Implicitly marking parameter $user as nullable is deprecated, the explicit nullable type must be used instead in twilio/sdk/src/Twilio/Http/CurlClient.php:21 
PHP Deprecated: Twilio\Http\CurlClient::request(): Implicitly marking parameter $password as nullable is deprecated, the explicit nullable type must be used instead in twilio/sdk/src/Twilio/Http/CurlClient.php:21 
PHP Deprecated: Twilio\Http\CurlClient::request(): Implicitly marking parameter $timeout as nullable is deprecated, the explicit nullable type must be used instead in twilio/sdk/src/Twilio/Http/CurlClient.php:21 
PHP Deprecated: Twilio\Http\CurlClient::options(): Implicitly marking parameter $user as nullable is deprecated, the explicit nullable type must be used instead in twilio/sdk/src/Twilio/Http/CurlClient.php:86 
PHP Deprecated: Twilio\Http\CurlClient::options(): Implicitly marking parameter $password as nullable is deprecated, the explicit nullable type must be used instead in twilio/sdk/src/Twilio/Http/CurlClient.php:86 
PHP Deprecated: Twilio\Http\CurlClient::options(): Implicitly marking parameter $timeout as nullable is deprecated, the explicit nullable type must be used instead in twilio/sdk/src/Twilio/Http/CurlClient.php:86 
PHP Deprecated: Twilio\Http\Client::request(): Implicitly marking parameter $user as nullable is deprecated, the explicit nullable type must be used instead in twilio/sdk/src/Twilio/Http/Client.php:8 
PHP Deprecated: Twilio\Http\Client::request(): Implicitly marking parameter $password as nullable is deprecated, the explicit nullable type must be used instead in twilio/sdk/src/Twilio/Http/Client.php:8 
PHP Deprecated: Twilio\Http\Client::request(): Implicitly marking parameter $timeout as nullable is deprecated, the explicit nullable type must be used instead in twilio/sdk/src/Twilio/Http/Client.php:8 

Technical details:

  • twilio-php version: 8.3.9
  • php version: 8.4.1
@ValiDrv
Copy link

ValiDrv commented Dec 19, 2024

same issue

@bobahvas
Copy link

Hey, guys. Any updates?
I see this PR that can fix issues without breaking changes #834

@adrianbj
Copy link
Author

Thanks, I hadn't seen that PR - would be great to get this committed.

@nikola-jovanovic-php
Copy link

i see there are few PRs merged to fix this deprecation warning, but I think it's not fixed completely as I still get deprecation warning on version 8.3.12.

for example, this line of code triggers deprecation: https://github.com/twilio/twilio-php/blob/main/src/Twilio/Rest/Chat/V1/ServiceList.php#L85

@phpfui
Copy link
Contributor

phpfui commented Jan 24, 2025

Yes, there are still generated files that don't properly type nullable parameters.

This library is generated with https://openapi-generator.tech, and that will need to support PHP 8.4. So if we can that fixed, the generator will automatically fix this library.

But the big issue here is https://openapi-generator.tech has LOTS of PRs, and still not one to support PHP 8.4

I am thinking running Rector on my version of the code base. I check in the source to me local repo so I don't reply on composer to install files.

It may be possible to add a rector step to post process this library until https://openapi-generator.tech adds PHP 8.4 support.

I will keep everyone posted.

@phpfui
Copy link
Contributor

phpfui commented Jan 24, 2025

So no need for Rector. PHP-CS-Fixer will do the work needed. I will submit a PR for this next week to add this to the CI pipeline. Basically:

$config = new PhpCsFixer\Config();
$config->setRules(['nullable_type_declaration_for_default_null_value' => true,]);

return $config->setFinder(PhpCsFixer\Finder::create()
			->exclude('vendor')
			->in(__DIR__.'/src/Twilio')
    );

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

No branches or pull requests

5 participants