Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

Yopai
Copy link
Contributor

@Yopai Yopai commented Feb 22, 2021

Q A
Branch? 4.4
Bug fix? yes
New feature? no
Deprecations? no
Tickets Fix #40200
License MIT
Doc PR no

In PHP8.1, a number of functions who were accepting null arguments will only accept
string ones.
(see https://wiki.php.net/rfc/deprecate_null_to_scalar_internal_arg)

In the polyfill, mb_* functions are already declared with a strict type checking of "string".

Therefore, it is necessary to get rid of the use of non string arguments when calling mb_* functions,
so that it won't break when either using the polyfill,or future php8 versions.

In every call where the argument may not be a string, this commit enforces the string type of the argument (with transtyping)

--- For reviewers

  • I generally don't like transtyping, but found it was the more "secure" way (on a non-BC point of view) here.
    Specially in Console/Helper/Table.php, where $cell can be an object (there are 2 "$cell instanceof ... tests)
    However, where the argument can already be either null or string (and not anything else), there may a beter approach ?

  • It's the first time I send a PR on symfony, so don't hesitate pointing me to thinks I've forgotten to done.

@carsonbot
Copy link

Hey!

I see that this is your first PR. That is great! Welcome!

Symfony has a contribution guide which I suggest you to read.

In short:

  • Always add tests
  • Keep backward compatibility (see https://symfony.com/bc).
  • Bug fixes must be submitted against the lowest maintained branch where they apply (see https://symfony.com/releases)
  • Features and deprecations must be submitted against the 5.x branch.

Review the GitHub status checks of your pull request and try to solve the reported issues. If some tests are failing, try to see if they are failing because of this change.

When two Symfony core team members approve this change, it will be merged and you will become an official Symfony contributor!
If this PR is merged in a lower version branch, it will be merged up to all maintained branches within a few days.

I am going to sit back now and wait for the reviews.

Cheers!

Carsonbot

@carsonbot carsonbot changed the title [console] [error_handler] [http_foundation] [mime] [translation] [var_dumper] [form] Handle calls to mb_ functions with non string arguments [Console][Form][Mime][Translation] [error_handler] [http_foundation] [var_dumper] Handle calls to mb_ functions with non string arguments Feb 22, 2021
@carsonbot carsonbot changed the title [Console][Form][Mime][Translation] [error_handler] [http_foundation] [var_dumper] Handle calls to mb_ functions with non string arguments [Console][ErrorHandler][Form][HttpFoundation][Mime][Translation][VarDumper] [error_handler] [http_foundation] [var_dumper] Handle calls to mb_ functions with non string arguments Feb 22, 2021
@derrabus derrabus changed the title [Console][ErrorHandler][Form][HttpFoundation][Mime][Translation][VarDumper] [error_handler] [http_foundation] [var_dumper] Handle calls to mb_ functions with non string arguments [Console][ErrorHandler][Form][HttpFoundation][Mime][Translation][VarDumper] Handle calls to mb_ functions with non string arguments Feb 22, 2021
@derrabus
Copy link
Member

Please also have a look at the CS errors fabbot reported.

@Yopai Yopai force-pushed the Change_mb_null_args branch from efdc0f9 to d0938cf Compare February 22, 2021 11:54
@Yopai
Copy link
Contributor Author

Yopai commented Feb 22, 2021

Thanks.
I fixed not-useful tests, and fix CS for what I modified.
And then I fixed use of shorttag, that fabbot indicated too.
(I pushed the commits again, is there anything else I have to do ?)

Copy link
Member

@derrabus derrabus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I should've been more precise. You don't need to fix fabbot errors you haven't caused. In this case, the short tags were a false positive. Can you restore them?

@Yopai Yopai force-pushed the Change_mb_null_args branch from 1c0f6b8 to 250ef7d Compare February 22, 2021 13:26
@Yopai
Copy link
Contributor Author

Yopai commented Feb 22, 2021

No worry (that's why I made it in a separate commit :) )
Done !

@Yopai Yopai force-pushed the Change_mb_null_args branch 2 times, most recently from 3830c75 to 4670282 Compare February 22, 2021 14:42
@Yopai Yopai force-pushed the Change_mb_null_args branch 2 times, most recently from 8459b70 to 274f7ac Compare February 22, 2021 17:16
@Yopai Yopai requested a review from nicolas-grekas February 22, 2021 17:17
In PHP8, a number of functions who were accepting null arguments will only accept
string ones.

In the polyfill, mb_* functions are declared with a trict type checking of "string".

Therefore, we deprecate the use of non string arguments, so that it won't break when either using the polyfill,
or future php8 versions.
@Yopai Yopai force-pushed the Change_mb_null_args branch from 274f7ac to ac45be2 Compare February 22, 2021 17:49
@Yopai Yopai changed the title [Console][ErrorHandler][Form][HttpFoundation][Mime][Translation][VarDumper] Handle calls to mb_ functions with non string arguments [Console] Handle calls to mb_ functions with non string arguments Feb 22, 2021
@carsonbot carsonbot changed the title [Console] Handle calls to mb_ functions with non string arguments [Console][ErrorHandler][Form][HttpFoundation][Mime][Translation][VarDumper] Handle calls to mb_ functions with non string arguments Feb 22, 2021
@nicolas-grekas nicolas-grekas changed the title [Console][ErrorHandler][Form][HttpFoundation][Mime][Translation][VarDumper] Handle calls to mb_ functions with non string arguments [Console] Handle calls to mb_ functions with non string arguments Feb 22, 2021
@nicolas-grekas
Copy link
Member

Thank you @Yopai.

@nicolas-grekas nicolas-grekas merged commit b5dc77e into symfony:4.4 Feb 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants