Commit acd342d82df for php.net
commit acd342d82dfaa6ebf65d073f23611c5656871016
Author: Gina Peter Banyard <girgias@php.net>
Date: Thu Aug 6 18:25:54 2026 +0100
Zend: deprecate passing a 3rd argument to define()
RFC: https://wiki.php.net/rfc/deprecations_php_8_6#deprecate_define_with_case_insensitive_being_specified
diff --git a/Zend/tests/builtin_functions/define_arg_3.phpt b/Zend/tests/builtin_functions/define_arg_3.phpt
new file mode 100644
index 00000000000..25d1b9dcf35
--- /dev/null
+++ b/Zend/tests/builtin_functions/define_arg_3.phpt
@@ -0,0 +1,25 @@
+--TEST--
+define() with 3rd argument
+--FILE--
+<?php
+
+define('my_Constant', 5, true);
+
+try {
+ var_dump(MY_CONSTANT);
+} catch (Throwable $e) {
+ echo $e::class, ': ', $e->getMessage(), PHP_EOL;
+}
+
+define('MY_CONSTANT', 5, false);
+var_dump(MY_CONSTANT);
+
+?>
+--EXPECTF--
+Deprecated: define(): Argument #3 ($case_insensitive) is ignored and treated as false since declaration of case-insensitive constants is no longer supported, passing the argument explicitly is unnecessary in %s on line %d
+
+Warning: define(): Argument #3 ($case_insensitive) is ignored since declaration of case-insensitive constants is no longer supported, this will be an error in PHP 9.0 in %s on line %d
+Error: Undefined constant "MY_CONSTANT"
+
+Deprecated: define(): Argument #3 ($case_insensitive) is ignored and treated as false since declaration of case-insensitive constants is no longer supported, passing the argument explicitly is unnecessary in %s on line %d
+int(5)
diff --git a/Zend/zend_builtin_functions.c b/Zend/zend_builtin_functions.c
index ed0507e0500..860413f8411 100644
--- a/Zend/zend_builtin_functions.c
+++ b/Zend/zend_builtin_functions.c
@@ -568,13 +568,25 @@ ZEND_FUNCTION(define)
Z_PARAM_BOOL(non_cs)
ZEND_PARSE_PARAMETERS_END();
+ if (ZEND_NUM_ARGS() == 3) {
+ zend_error(E_DEPRECATED,
+ "define(): Argument #3 ($case_insensitive) is ignored and treated as false since declaration of case-insensitive constants is no longer supported, passing the argument explicitly is unnecessary"
+ );
+ if (UNEXPECTED(EG(exception))) {
+ RETURN_THROWS();
+ }
+ }
+
if (zend_memnstr(ZSTR_VAL(name), "::", sizeof("::") - 1, ZSTR_VAL(name) + ZSTR_LEN(name))) {
zend_argument_value_error(1, "cannot be a class constant");
RETURN_THROWS();
}
if (non_cs) {
- zend_error(E_WARNING, "define(): Argument #3 ($case_insensitive) is ignored since declaration of case-insensitive constants is no longer supported");
+ zend_error(E_WARNING, "define(): Argument #3 ($case_insensitive) is ignored since declaration of case-insensitive constants is no longer supported, this will be an error in PHP 9.0");
+ if (UNEXPECTED(EG(exception))) {
+ RETURN_THROWS();
+ }
}
if (Z_TYPE_P(val) == IS_ARRAY && Z_REFCOUNTED_P(val)) {