Commit 2bddba4db77 for php.net
commit 2bddba4db77b7264c0b4b48771ced67a3e758a5a
Author: Gina Peter Banyard <girgias@php.net>
Date: Mon Jul 27 20:20:11 2026 +0100
streams: use C enums instead of define for error_{store_}mode (#22901)
Also make private as these are not used outside of the file.
diff --git a/main/streams/php_stream_errors.h b/main/streams/php_stream_errors.h
index 67112c8932b..878350f972a 100644
--- a/main/streams/php_stream_errors.h
+++ b/main/streams/php_stream_errors.h
@@ -21,18 +21,6 @@
BEGIN_EXTERN_C()
-/* Error mode context options (internal C constants) */
-#define PHP_STREAM_ERROR_MODE_ERROR 0
-#define PHP_STREAM_ERROR_MODE_EXCEPTION 1
-#define PHP_STREAM_ERROR_MODE_SILENT 2
-
-/* Error store context options (internal C constants) */
-#define PHP_STREAM_ERROR_STORE_AUTO 0
-#define PHP_STREAM_ERROR_STORE_NONE 1
-#define PHP_STREAM_ERROR_STORE_NON_TERM 2
-#define PHP_STREAM_ERROR_STORE_TERMINAL 3
-#define PHP_STREAM_ERROR_STORE_ALL 4
-
/* Maximum operation nesting depth */
#define PHP_STREAM_ERROR_MAX_DEPTH 1000
/* Operations pool size to prevent extra allocations */
diff --git a/main/streams/stream_errors.c b/main/streams/stream_errors.c
index 5b52bad1e1a..067a604af78 100644
--- a/main/streams/stream_errors.c
+++ b/main/streams/stream_errors.c
@@ -83,8 +83,23 @@ static void php_stream_error_create_array(zval *zv, php_stream_error_entry *firs
}
/* Context option helpers */
-
-static int php_stream_auto_decide_error_store_mode(int error_mode)
+/* Error mode context options (internal C constants) */
+C23_ENUM(php_stream_error_mode, uint8_t) {
+ PHP_STREAM_ERROR_MODE_ERROR = 0,
+ PHP_STREAM_ERROR_MODE_EXCEPTION = 1,
+ PHP_STREAM_ERROR_MODE_SILENT = 2
+};
+
+/* Error store context options (internal C constants) */
+C23_ENUM(php_stream_error_store, uint8_t) {
+ PHP_STREAM_ERROR_STORE_AUTO = 0,
+ PHP_STREAM_ERROR_STORE_NONE = 1,
+ PHP_STREAM_ERROR_STORE_NON_TERM = 2,
+ PHP_STREAM_ERROR_STORE_TERMINAL = 3,
+ PHP_STREAM_ERROR_STORE_ALL = 4
+};
+
+static php_stream_error_store php_stream_auto_decide_error_store_mode(php_stream_error_mode error_mode)
{
switch (error_mode) {
case PHP_STREAM_ERROR_MODE_ERROR:
@@ -98,7 +113,7 @@ static int php_stream_auto_decide_error_store_mode(int error_mode)
}
}
-static int php_stream_get_error_mode(php_stream_context *context)
+static php_stream_error_mode php_stream_get_error_mode(php_stream_context *context)
{
if (!context) {
return PHP_STREAM_ERROR_MODE_ERROR;
@@ -127,7 +142,8 @@ static int php_stream_get_error_mode(php_stream_context *context)
return PHP_STREAM_ERROR_MODE_ERROR;
}
-static int php_stream_get_error_store_mode(php_stream_context *context, int error_mode)
+static php_stream_error_store php_stream_get_error_store_mode(
+ php_stream_context *context, php_stream_error_mode error_mode)
{
if (!context) {
return php_stream_auto_decide_error_store_mode(error_mode);
@@ -386,7 +402,7 @@ static void php_stream_throw_exception_with_errors(php_stream_error_operation *o
}
static void php_stream_report_errors(php_stream_context *context, php_stream_error_operation *op,
- int error_mode, bool is_terminating)
+ php_stream_error_mode error_mode, bool is_terminating)
{
switch (error_mode) {
case PHP_STREAM_ERROR_MODE_ERROR: {
@@ -439,8 +455,8 @@ PHPAPI void php_stream_error_operation_end(php_stream_context *context)
context = FG(default_context);
}
- int error_mode = php_stream_get_error_mode(context);
- int store_mode = php_stream_get_error_store_mode(context, error_mode);
+ php_stream_error_mode error_mode = php_stream_get_error_mode(context);
+ php_stream_error_store store_mode = php_stream_get_error_store_mode(context, error_mode);
bool is_terminating = php_stream_has_terminating_error(op);