Skip to content

Coding Standards: Pass $count to the second _list_meta_row() call - #13227

Open
csemazharul wants to merge 1 commit into
WordPress:trunkfrom
csemazharul:fix/ajax-add-meta-undefined-c
Open

Coding Standards: Pass $count to the second _list_meta_row() call#13227
csemazharul wants to merge 1 commit into
WordPress:trunkfrom
csemazharul:fix/ajax-add-meta-undefined-c

Conversation

@csemazharul

@csemazharul csemazharul commented Aug 21, 2026

Copy link
Copy Markdown

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

While reading wp_ajax_add_meta() I noticed it passes a variable that doesn't exist.

In [61224] the variable $c was renamed to $count. It's used in three places, but only two of them were changed:

// src/wp-admin/includes/ajax-actions.php

$count = 0;                           // line 1637 - changed
_list_meta_row( $meta, $count )       // line 1703 - changed
_list_meta_row( array( ... ), $c )    // line 1750 - still says $c

So the last call passes $c, and $c isn't defined anywhere in the function.

Normally PHP would warn about that. It doesn't here, because the second argument is taken by reference:

function _list_meta_row( $entry, &$count ) {

When you pass an undefined variable by reference, PHP just creates it and sets it to null. No notice, no error. That's also why PHPStan doesn't flag it - $c is missing from tests/phpstan/baselines/variable.undefined.neon, even though five other variables from this same file are listed there.

This changes that one line to $count.

What breaks

Nothing right now. $count is never read after either call, since $response->send() runs immediately, so the output is identical before and after.

I'm raising it because the two calls no longer match each other, and if someone uses $count after that call later on, it will quietly hold the wrong value.

Testing

tests/phpunit/tests/ajax/wpAjaxAddMeta.php already covers this code path in test_wp_ajax_add_meta_allows_empty_values_on_updating():

phpunit --filter test_wp_ajax_add_meta

It passes before and after, which is what you'd expect since the behavior doesn't change.

Affects 7.0, 7.1 and trunk. 6.9 and earlier are fine - they still use $c in all three places.

[61224] renamed $c to $count in wp_ajax_add_meta(), but only two of the
three occurrences were updated. The _list_meta_row() call in the branch
that updates existing meta still passes $c, which is no longer defined
anywhere in the function.

_list_meta_row() takes its second argument by reference, so PHP creates
the variable rather than emitting an undefined variable warning. That is
also why static analysis does not catch it: $c is absent from
tests/phpstan/baselines/variable.undefined.neon even though five other
variables in this file are listed there.

Nothing reads $count after either call, so there is no change in output.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props mazharul78.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@github-actions

Copy link
Copy Markdown

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

@csemazharul csemazharul changed the title Administration: Pass $count to the second _list_meta_row() call Coding Standards: Pass $count to the second _list_meta_row() call Aug 21, 2026
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.

1 participant