[php-src] master: Zend: deprecate naming a function readonly
Gina Peter Banyard <[email protected]>
| Newsgroups | gmane.comp.php.cvs.general |
|---|---|
| Message-ID | <[email protected]> |
Author: Gina Peter Banyard (Girgias)
Date: 2026-08-10T18:21:19+01:00
Commit: https://github.com/php/php-src/commit/a9ba369abe43a4947e4015171f0111c4a816a630
Raw diff: https://github.com/php/php-src/commit/a9ba369abe43a4947e4015171f0111c4a816a630.diff
Zend: deprecate naming a function readonly
RFC: https://wiki.php.net/rfc/deprecations_php_8_6#deprecate_the_possibility_to_name_a_function_readonly
Changed paths:
A Zend/tests/functions/readonly_as_fn_name_is_deprecated.phpt
A Zend/tests/functions/readonly_as_fn_name_is_deprecated_namespaced.phpt
A Zend/tests/functions/readonly_as_fn_name_is_deprecated_throw_handler.phpt
A Zend/tests/functions/readonly_as_method_name_is_ok.phpt
M Zend/tests/grammar/readonly_function.phpt
M Zend/zend_compile.c
Diff:
diff --git a/Zend/tests/functions/readonly_as_fn_name_is_deprecated.phpt b/Zend/tests/functions/readonly_as_fn_name_is_deprecated.phpt
new file mode 100644
index 000000000000..2ac975dcf654
--- /dev/null
+++ b/Zend/tests/functions/readonly_as_fn_name_is_deprecated.phpt
@@ -0,0 +1,12 @@
+--TEST--
+Naming a function readonly is deprecated
+--FILE--
+<?php
+
+function readonly() {}
+
+?>
+DONE
+--EXPECTF--
+Deprecated: Calling a function “readonly” is deprecated in %s on line %d
+DONE
diff --git a/Zend/tests/functions/readonly_as_fn_name_is_deprecated_namespaced.phpt b/Zend/tests/functions/readonly_as_fn_name_is_deprecated_namespaced.phpt
new file mode 100644
index 000000000000..f4b39d6c3e5a
--- /dev/null
+++ b/Zend/tests/functions/readonly_as_fn_name_is_deprecated_namespaced.phpt
@@ -0,0 +1,14 @@
+--TEST--
+Naming a function readonly is deprecated
+--FILE--
+<?php
+
+namespace Foo;
+
+function readonly() {}
+
+?>
+DONE
+--EXPECTF--
+Deprecated: Calling a function “readonly” is deprecated in %s on line %d
+DONE
diff --git a/Zend/tests/functions/readonly_as_fn_name_is_deprecated_throw_handler.phpt b/Zend/tests/functions/readonly_as_fn_name_is_deprecated_throw_handler.phpt
new file mode 100644
index 000000000000..428bd339d111
--- /dev/null
+++ b/Zend/tests/functions/readonly_as_fn_name_is_deprecated_throw_handler.phpt
@@ -0,0 +1,17 @@
+--TEST--
+Naming a function readonly is deprecated with an error handler elevating it to an exception
+--FILE--
+<?php
+
+set_error_handler(function ($number, $message) {
+ throw new Exception($message);
+});
+
+/* Throwing error handlers do no apply for compile time deprecations */
+function readonly() {}
+
+?>
+DONE
+--EXPECTF--
+Deprecated: Calling a function “readonly” is deprecated in %s on line %d
+DONE
diff --git a/Zend/tests/functions/readonly_as_method_name_is_ok.phpt b/Zend/tests/functions/readonly_as_method_name_is_ok.phpt
new file mode 100644
index 000000000000..373fa735365b
--- /dev/null
+++ b/Zend/tests/functions/readonly_as_method_name_is_ok.phpt
@@ -0,0 +1,13 @@
+--TEST--
+Naming a function readonly is deprecated
+--FILE--
+<?php
+
+class C {
+ public function readonly() {}
+}
+
+?>
+DONE
+--EXPECT--
+DONE
diff --git a/Zend/tests/grammar/readonly_function.phpt b/Zend/tests/grammar/readonly_function.phpt
index 35102d36b9dc..c1592aa1fe8c 100644
--- a/Zend/tests/grammar/readonly_function.phpt
+++ b/Zend/tests/grammar/readonly_function.phpt
@@ -32,7 +32,8 @@ $b->readonly();
echo $b->readonly, "\n";
?>
---EXPECT--
+--EXPECTF--
+Deprecated: Calling a function “readonly” is deprecated in %s on line %d
Hi!
Const hi!
Static hi!
diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c
index 882b1bf990bf..92807513bc6a 100644
--- a/Zend/zend_compile.c
+++ b/Zend/zend_compile.c
@@ -8931,6 +8931,10 @@ static zend_string *zend_begin_func_decl(znode *result, zend_op_array *op_array,
"__autoload() is no longer supported, use spl_autoload_register() instead");
}
+ if (zend_string_equals_literal_ci(unqualified_name, "readonly")) {
+ zend_error(E_DEPRECATED, "Calling a function “readonly” is deprecated");
+ }
+
if (zend_string_equals_literal_ci(unqualified_name, "assert")) {
zend_error(E_COMPILE_ERROR,
"Defining a custom assert() function is not allowed, "