Skip to content

Add missing return statement to _mb_ord()#12020

Open
westonruter wants to merge 1 commit into
WordPress:trunkfrom
westonruter:fix/mb-ord-return
Open

Add missing return statement to _mb_ord()#12020
westonruter wants to merge 1 commit into
WordPress:trunkfrom
westonruter:fix/mb-ord-return

Conversation

@westonruter
Copy link
Copy Markdown
Member

This is a follow-up to #11965.

There is a PHPStan rule level 0 error introduced in that PR:

 ------ ----------------------------------------------------------------------------- 
  Line   src/wp-includes/compat.php                                                   
 ------ ----------------------------------------------------------------------------- 
  227    Function _mb_ord() should return int|false but return statement is missing.  
         🪪  return.missing                                                           
         at src/wp-includes/compat.php:227                                            
 ------ ----------------------------------------------------------------------------- 

While it doesn't seem that $byte_length can ever be anything other than int<1, 4> when 1 !== $found_count, this is not picked up by PHPStan, leading ot the error.

An alternative to this would be to declare the type:

diff --git a/src/wp-includes/compat.php b/src/wp-includes/compat.php
index 5eb467280a..d67cea2d0c 100644
--- a/src/wp-includes/compat.php
+++ b/src/wp-includes/compat.php
@@ -221,6 +221,8 @@ function _mb_ord( $string, $encoding = null ) {
 		return false;
 	}
 
+	/** @var int<1, 4> $byte_length */
+
 	// These are valid code points, so no further validation is required.
 	$b0 = ord( $string[0] );

But this seems less clean.

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

Use of AI Tools

None


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.

@westonruter westonruter requested a review from dmsnell May 30, 2026 21:38
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 30, 2026

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 westonruter, dmsnell.

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.

@dmsnell
Copy link
Copy Markdown
Member

dmsnell commented May 31, 2026

Thanks @westonruter — the inline comment is probably better semantically but the return false would potentially make up for any regressions that would creep into _wp_scan_utf8(), as unlikely as those are.

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.

2 participants