Coding Standards: Pass $count to the second _list_meta_row() call - #13227
Coding Standards: Pass $count to the second _list_meta_row() call#13227csemazharul wants to merge 1 commit into
Conversation
[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>
|
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 Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Test using WordPress PlaygroundThe 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
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
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
$cwas renamed to$count. It's used in three places, but only two of them were changed:So the last call passes
$c, and$cisn't defined anywhere in the function.Normally PHP would warn about that. It doesn't here, because the second argument is taken by reference:
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 -
$cis missing fromtests/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.
$countis 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
$countafter that call later on, it will quietly hold the wrong value.Testing
tests/phpunit/tests/ajax/wpAjaxAddMeta.phpalready covers this code path intest_wp_ajax_add_meta_allows_empty_values_on_updating():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
$cin all three places.