commit da83966fa13e866c1d00b6eec45d963948fb08b7
Author: Ayesh Karunaratne <ayesh@aye.sh>
Date:   Mon Aug 2 19:51:55 2021 +0530

    Extract readonly function

diff --git a/src/wp-includes/PHP_Compat/readonly.php b/src/wp-includes/PHP_Compat/readonly.php
new file mode 100644
index 0000000000..a441f03c94
--- /dev/null
+++ b/src/wp-includes/PHP_Compat/readonly.php
@@ -0,0 +1,34 @@
+<?php
+
+/**
+ * Conditionally declares a `readonly` function, which was renamed to
+ * `wp_readonly` in WordPress 5.9.
+ *
+ * In order to avoid PHP parser errors, this function was extracted to
+ * this separate file, and only included conditionally on PHP 8.1.
+ *
+ * Including this file on PHP >= 8.1 results in a fatal error.
+ *
+ * @package WordPress
+ * @subpackage oEmbed
+ */
+
+/**
+ * Outputs the HTML readonly attribute.
+ *
+ * Compares the first two arguments and if identical marks as readonly
+ *
+ * This function is deprecated, and cannot be used on PHP >= 8.1.
+ * @see wp_readonly
+ *
+ * @since 4.9.0
+ * @deprecated 5.9.0
+ *
+ * @param mixed $readonly One of the values to compare
+ * @param mixed $current  (true) The other value to compare if not just true
+ * @param bool  $echo     Whether to echo or just return the string
+ * @return string HTML attribute or empty string
+ */
+function readonly( $readonly, $current = true, $echo = true ) {
+	return wp_readonly( $readonly, $current, $echo );
+}
diff --git a/src/wp-includes/general-template.php b/src/wp-includes/general-template.php
index ab8877f7be..d54441cab5 100644
--- a/src/wp-includes/general-template.php
+++ b/src/wp-includes/general-template.php
@@ -4813,17 +4813,29 @@ function disabled( $disabled, $current = true, $echo = true ) {
  *
  * Compares the first two arguments and if identical marks as readonly
  *
- * @since 4.9.0
+ * @since 5.9.0
  *
  * @param mixed $readonly One of the values to compare
  * @param mixed $current  (true) The other value to compare if not just true
  * @param bool  $echo     Whether to echo or just return the string
  * @return string HTML attribute or empty string
  */
-function readonly( $readonly, $current = true, $echo = true ) {
+function wp_readonly( $readonly, $current = true, $echo = true ) {
 	return __checked_selected_helper( $readonly, $current, $echo, 'readonly' );
 }
 
+/**
+ * Include a compat `readonly` function on PHP < 8.1. Since PHP 8.1,
+ * `readonly` is a reserved keyword, and it is not possible to use
+ * it as a function name. In order to maintain compatibility with
+ * existing functions, this function was extracted to a separate file,
+ * and included on PHP < 8.1.
+ */
+if (PHP_VERSION_ID < 80100) {
+	require_once __DIR__ . '/PHP_Compat/readonly.php';
+}
+
+
 /**
  * Private helper function for checked, selected, disabled and readonly.
  *
