Commit 0a8133032b4 for php.net

commit 0a8133032b4b7d599759d9e5e229ac045eb67834
Author: Ilija Tovilo <ilija.tovilo@me.com>
Date:   Sat Jun 20 15:08:12 2026 +0200

    Use zend_enum_fetch_case_id() for poll API (GH-22367)

diff --git a/ext/standard/io_poll.c b/ext/standard/io_poll.c
index e8366c7e880..c048d43ccb4 100644
--- a/ext/standard/io_poll.c
+++ b/ext/standard/io_poll.c
@@ -85,26 +85,7 @@ static inline void php_io_poll_throw_failed_operation(
 /* Event enum to bit mask mapping */
 static uint32_t php_io_poll_event_enum_to_bit(zend_object *event_enum)
 {
-	zval *case_name = zend_enum_fetch_case_name(event_enum);
-	const char *name = Z_STRVAL_P(case_name);
-
-	if (strcmp(name, "Read") == 0) {
-		return PHP_POLL_READ;
-	} else if (strcmp(name, "Write") == 0) {
-		return PHP_POLL_WRITE;
-	} else if (strcmp(name, "Error") == 0) {
-		return PHP_POLL_ERROR;
-	} else if (strcmp(name, "HangUp") == 0) {
-		return PHP_POLL_HUP;
-	} else if (strcmp(name, "ReadHangUp") == 0) {
-		return PHP_POLL_RDHUP;
-	} else if (strcmp(name, "OneShot") == 0) {
-		return PHP_POLL_ONESHOT;
-	} else if (strcmp(name, "EdgeTriggered") == 0) {
-		return PHP_POLL_ET;
-	}
-
-	return 0;
+	return 1 << (zend_enum_fetch_case_id(event_enum) - 1);
 }

 static uint32_t php_io_poll_event_enums_to_events(zval *event_enums)
@@ -179,24 +160,7 @@ static zend_result php_io_poll_events_to_event_enums(uint32_t events, zval *even
 /* Backend enum name to backend type mapping */
 static php_poll_backend_type php_io_poll_backend_enum_to_type(zend_object *backend_enum)
 {
-	zval *case_name = zend_enum_fetch_case_name(backend_enum);
-	const char *name = Z_STRVAL_P(case_name);
-
-	if (strcmp(name, "Auto") == 0) {
-		return PHP_POLL_BACKEND_AUTO;
-	} else if (strcmp(name, "Poll") == 0) {
-		return PHP_POLL_BACKEND_POLL;
-	} else if (strcmp(name, "Epoll") == 0) {
-		return PHP_POLL_BACKEND_EPOLL;
-	} else if (strcmp(name, "Kqueue") == 0) {
-		return PHP_POLL_BACKEND_KQUEUE;
-	} else if (strcmp(name, "EventPorts") == 0) {
-		return PHP_POLL_BACKEND_EVENTPORT;
-	} else if (strcmp(name, "WSAPoll") == 0) {
-		return PHP_POLL_BACKEND_WSAPOLL;
-	}
-
-	return PHP_POLL_BACKEND_AUTO;
+	return zend_enum_fetch_case_id(backend_enum) - 2;
 }

 static const char *php_io_poll_backend_type_to_name(php_poll_backend_type type)
diff --git a/ext/standard/io_poll.stub.php b/ext/standard/io_poll.stub.php
index 82bc00e0aac..83c1ba5cbe2 100644
--- a/ext/standard/io_poll.stub.php
+++ b/ext/standard/io_poll.stub.php
@@ -1,6 +1,9 @@
 <?php

-/** @generate-class-entries */
+/**
+ * @generate-class-entries
+ * @generate-c-enums
+ */

 namespace Io {
     class IoException extends \Exception {}
@@ -8,6 +11,7 @@ class IoException extends \Exception {}

 namespace Io\Poll {

+    // Keep in sync with main/php_poll.h!
     enum Backend
     {
         case Auto;
@@ -25,6 +29,7 @@ public function isAvailable(): bool {}
         public function supportsEdgeTriggering(): bool {}
     }

+    // Keep in sync with main/php_poll.h!
     enum Event {
         case Read;
         case Write;
diff --git a/ext/standard/io_poll_arginfo.h b/ext/standard/io_poll_arginfo.h
index ced48021eaa..5fc62f62956 100644
Binary files a/ext/standard/io_poll_arginfo.h and b/ext/standard/io_poll_arginfo.h differ
diff --git a/ext/standard/io_poll_decl.h b/ext/standard/io_poll_decl.h
new file mode 100644
index 00000000000..2b09e3665f5
Binary files /dev/null and b/ext/standard/io_poll_decl.h differ
diff --git a/main/php_poll.h b/main/php_poll.h
index c7305271294..708d957b89e 100644
--- a/main/php_poll.h
+++ b/main/php_poll.h
@@ -24,7 +24,7 @@

 /* clang-format off */

-/* Event types */
+/* Event types. Keep in sync with io_poll.stub.php! */
 #define PHP_POLL_READ    0x01
 #define PHP_POLL_WRITE   0x02
 #define PHP_POLL_ERROR   0x04
@@ -37,7 +37,7 @@
 #define PHP_POLL_FLAG_PERSISTENT 0x01
 #define PHP_POLL_FLAG_RAW_EVENTS 0x02

-/* Poll backend types */
+/* Poll backend types. Keep in sync with io_poll.stub.php! */
 typedef enum {
 	PHP_POLL_BACKEND_AUTO = -1,
 	PHP_POLL_BACKEND_POLL = 0,