Skip to content

Conversation

@hugosolar
Copy link

This may be an edge case for posts created with Classic editor or classic editor block.
_process_directives function within WP_Interactivity_API class will process html and check for closer tags.
if there's a wrong tag like </br> (in my case) will result in a TypeError:

Fatal error: Uncaught TypeError: count(): Argument #1 ($value) must be of type Countable|array, null given in wp-includes/interactivity-api/class-wp-interactivity-api.php on line 442

by checking the line of code, count() function is applied to get_attribute_names_with_prefix() method from WP_HTML_Tag_Processor which can eventually return null

for newer PHP version (8.0.0 and later) this will throw a fatal error.
probably worth getting an extra check if the funcion is returning a countable variable

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

@github-actions
Copy link

Hi @hugosolar! 👋

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 the Core Handbook.

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

@github-actions
Copy link

github-actions bot commented Aug 27, 2025

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 hugosolar, jonsurrell, darerodz.

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

@github-actions
Copy link

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

  • The Plugin and Theme Directories cannot be accessed within Playground.
  • 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.

Copy link
Member

@sirreal sirreal left a comment

Choose a reason for hiding this comment

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

Thanks @hugosolar! Did you consider adding a unit test that covers this?

This change seems good to me but I'd like @luisherranz and/or @DAreRodz to review.

} else {
if ( 0 !== count( $p->get_attribute_names_with_prefix( 'data-wp-each-child' ) ) ) {
$each_child_attrs = $p->get_attribute_names_with_prefix( 'data-wp-each-child' );
if ( ! is_countable( $each_child_attrs ) ) {
Copy link
Member

Choose a reason for hiding this comment

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

I'd prefer a null check here, it's more consistent with other HTML API code:

Suggested change
if ( ! is_countable( $each_child_attrs ) ) {
if ( null === $each_child_attrs ) {

Copy link

@DAreRodz DAreRodz left a comment

Choose a reason for hiding this comment

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

Nice catch, @hugosolar. 🙂

I left a comment. I would be great if you could add a unit test for this case, as @sirreal mentioned. Unit tests for the Interactivity API are inside the tests/phpunit/tests/interactivity-api folder.

Comment on lines 443 to 447
if ( ! is_countable( $each_child_attrs ) ) {
continue;
}

if ( 0 !== count( $each_child_attrs ) ) {

Choose a reason for hiding this comment

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

I'm not 100% sure right now, but I think the else block below should execute when $each_child_attrs is null, shouldn't it?

At least that's the behavior in PHP < 8.0, when count() returned 0 if null is passed.

Suggested change
if ( ! is_countable( $each_child_attrs ) ) {
continue;
}
if ( 0 !== count( $each_child_attrs ) ) {
if ( null !== $each_child_attrs && 0 !== count( $each_child_attrs ) ) {

Copy link
Member

Choose a reason for hiding this comment

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

I think you're right. I thought it only contained a foreach with another get_attribute_names_with_prefix() but it contains another conditional block.

That other get_attribute_names_with_prefix has the same problem where it lacks a null check.

@sirreal
Copy link
Member

sirreal commented Oct 1, 2025

👋 @hugosolar Just checking in, are you able to finish this up or would you like some help? The next release is approaching and it would be nice to get this fix in place.

@hugosolar
Copy link
Author

@sirreal I've pushed the fix that seems to work better regarding the tests I've made here
Also, added one test to verify if </br> is breaking _process_directive function
I tested it locally and it's passing but not sure why it's failing in the pipelines
would you help me to figure what's the issue here?

The error is throwing this

Parse error: syntax error, unexpected ')' in /var/www/tests/phpunit/tests/interactivity-api/wpInteractivityAPI.php on line 1272

checked that line but can't see anything wrong with it

@hugosolar
Copy link
Author

Thanks for the help @sirreal !
I think this is ready for a CR

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.

3 participants