Skip to content

Conversation

@RockonShajib3
Copy link

@RockonShajib3 RockonShajib3 commented Nov 27, 2022

Trac ticket: https://core.trac.wordpress.org/ticket/57213


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

@github-actions
Copy link

Hi @RockonShajib3! 👋

Thank you for your contribution to WordPress! 💖

It looks like this is your first pull request to wordpress-develop. Here are a few things to be aware of that may help you out!

No one monitors this repository for new pull requests. Pull requests must be attached to a Trac ticket to be considered for inclusion in WordPress Core. To attach a pull request to a Trac ticket, please include the ticket's full URL in your pull request description.

Pull requests are never merged on GitHub. The WordPress codebase continues to be managed through the SVN repository that this GitHub repository mirrors. Please feel free to open pull requests to work on any contribution you are making.

More information about how GitHub pull requests can be used to contribute to WordPress can be found in this blog post.

Please include automated tests. Including tests in your pull request is one way to help your patch be considered faster. To learn about WordPress' test suites, visit the Automated Testing page in the handbook.

If you have not had a chance, please review the Contribute with Code page in the WordPress Core Handbook.

The Developer Hub also documents the various coding standards that are followed:

Thank you,
The WordPress Project


// Avoid the array_slice() if possible.
if ( 0 == $the_['accepted_args'] ) {
if ( 0 === $the_['accepted_args'] ) {
Copy link
Contributor

@costdev costdev Nov 27, 2022

Choose a reason for hiding this comment

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

  • While this continues to avoid array_slice() for (int) 0, the loose comparison meant that (string) '0' (and anything that evaluated to 0), also avoided array_slice().
  • With the strict comparison, (string) '0' now passes through to else, and array_slice() is called.

$accepted_args is documented as int, and I think it would be incredibly rare for the following code:

add_filter( 'hook_name', 'callback_name', $priority, '0' );

However, it may be worth considering whether the following check would be appropriate for the sake of preventing a performance regression for those (very rare) cases:

if ( 0 === $the_['accepted_args'] || '0' === $the_['accepted_args'] ) {

Or, for full BC:

if ( 0 === (int) $the_['accepted_args'] ) {

@mukeshpanchal27 Thoughts?

Copy link
Member

Choose a reason for hiding this comment

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

Thanks @costdev.

The second approach, in my opinion, is a better way to solve the problem.

if ( 0 === (int) $the_['accepted_args'] ) {


// Avoid the array_slice() if possible.
if ( 0 == $the_['accepted_args'] ) {
if ( 0 === $the_['accepted_args'] ) {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if ( 0 === $the_['accepted_args'] ) {
if ( 0 === (int) $the_['accepted_args'] ) {

@SergeyBiryukov
Copy link
Member

Thanks for the PR! This was merged in r56511.

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

Successfully merging this pull request may close these issues.

4 participants