Skip to content

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

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

Closed
adrianbj opened this issue Dec 18, 2024 · 21 comments · Fixed by twilio/twilio-oai-generator#644
Closed
Labels
dependencies pull requests that update a dependency file priority: high Needs immediate attention; blockers or critical or bug

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')
    );

@mreiden
Copy link

mreiden commented Feb 6, 2025

OpenAPI version 7.11.0 states they've added explicit null declarations.

[php] Follow PHP8.4 update: declared nullable parameters explicitly OpenAPITools/openapi-generator#20243

@sapphirecat
Copy link

Still seeing issues on Twilio SDK 8.3.15, when sending an SMS:

PHP Deprecated: Twilio\\Rest\\Api\\V2010\\Account\\MessageList::read(): Implicitly marking parameter $limit as nullable is deprecated, the explicit nullable type must be used instead in /…/vendor/twilio/sdk/src/Twilio/Rest/Api/V2010/Account/MessageList.php on line 142
PHP Deprecated: Twilio\\Rest\\Api\\V2010\\Account\\MessageList::stream(): Implicitly marking parameter $limit as nullable is deprecated, the explicit nullable type must be used instead in /…/vendor/twilio/sdk/src/Twilio/Rest/Api/V2010/Account/MessageList.php on line 166
PHP Deprecated: Twilio\\Rest\\Api\\V2010\\Account\\MessageInstance::__construct(): Implicitly marking parameter $sid as nullable is deprecated, the explicit nullable type must be used instead in /…/vendor/twilio/sdk/src/Twilio/Rest/Api/V2010/Account/MessageInstance.php on line 65

@phpfui
Copy link
Contributor

phpfui commented Mar 5, 2025 via email

@hivokas
Copy link

hivokas commented Mar 6, 2025

I have this one:

Twilio\Rest\Lookups\V2\PhoneNumberInstance::__construct(): Implicitly marking parameter $phoneNumber as nullable is deprecated, the explicit nullable type must be used instead

@adrianbj
Copy link
Author

Nearly 4 months after 8.4's release and we still don't have official support. Come on Twilio!

@phpfui
Copy link
Contributor

phpfui commented Mar 14, 2025 via email

@mbabker
Copy link

mbabker commented Mar 20, 2025

Well, for those who aren't interested in waiting for Twilio to fix this issue in any of the ways that have been proposed thus far, you can use this patch alongside cweagans/composer-patches to silence all of the SDK's deprecations. This patch was freshly this morning after updating to the 8.4.1 release using the PHP-CS-FIxer config in #835 (comment) to do all the heavy lifting.

@faytekin
Copy link

same issue

@epicentre
Copy link

Please fix this issue. I cannot upgrade my projects to php 8.4.

@tiwarishubham635
Copy link
Contributor

Hi everyone! Please take a look at these changes that will be introduced to fix this issue. Since the files are autogenerated, I have raised this PR for the fix. Please add a +1 to the PR to confirm that I am not missing anything. Thanks!

@tiwarishubham635 tiwarishubham635 added dependencies pull requests that update a dependency file priority: high Needs immediate attention; blockers or critical or bug labels Apr 16, 2025
@phpfui
Copy link
Contributor

phpfui commented May 7, 2025

I just installed dev-main with Composer and the issue is still not fixed. Let me know when you think it is and I can try again.

@tiwarishubham635
Copy link
Contributor

The changes have been merged and this issue will be resolved in the next release. Thanks!

@adrianbj
Copy link
Author

@tiwarishubham635 - we've had a lot of releases since this has been closed, but the ReadMe still doesn't list 8.4 as being supported. Is that a documentation error, or is this still waiting to be merged?

@tiwarishubham635
Copy link
Contributor

This is a documentation issue. Let me update the readme right away

@tiwarishubham635
Copy link
Contributor

Here is the PR - #868. I hope it this works for you?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dependencies pull requests that update a dependency file priority: high Needs immediate attention; blockers or critical or bug
Projects
None yet