Skip to content

Commit 87d0030

Browse files
domr@qq.comdomr@qq.com
authored andcommitted
Backport PHP 8.6 compatibility for the shipped extensions
1 parent 1820e73 commit 87d0030

9 files changed

Lines changed: 3266 additions & 9 deletions

File tree

‎.github/jit/apply_spc_profile.py‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,17 @@
3131
raise RuntimeError('Unexpected static-php-cli PHP 8.6 compatibility layout')
3232
text = text.replace(before, after, 1)
3333
path.write_text(text)
34+
35+
path = Path('src/Package/Target/php.php')
36+
text = path.read_text()
37+
before = ' foreach (FileSystem::scanDirFiles($build_dir) ?: [] as $file) {'
38+
if text.count(before) != 1:
39+
raise RuntimeError('Unexpected static-php-cli PHP 8.6 extension patch layout')
40+
path.write_text(text.replace(before, ''' $patch_dir = getenv('SPC_PHP86_PATCH_DIR');
41+
if ($patch_dir !== false) {
42+
$patch_path = $patch_dir . '/' . $ext->getExtensionName() . '.patch';
43+
if (is_file($patch_path)) {
44+
shell()->cd($build_dir)->exec('patch --batch -p1 -i ' . escapeshellarg($patch_path));
45+
}
46+
}
47+
''' + before, 1))
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.patch -whitespace

‎.github/patches/php86/apcu.patch‎

Lines changed: 201 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,201 @@
1+
From 95f9ab828f95c6ca5877e584ead109189d0cec61 Mon Sep 17 00:00:00 2001
2+
From: Andy Postnikov <apostnikov@gmail.com>
3+
Date: Thu, 30 Apr 2026 20:43:38 +0200
4+
Subject: [PATCH] Replace XtOffsetOf() with offsetof() for PHP 8.6
5+
6+
PHP 8.6 removed XtOffsetOf(), which was an alias for the standard C
7+
offsetof() macro. Replace all usages in apc_cache.h and apc_iterator
8+
with offsetof() directly.
9+
10+
Ref: https://github.com/php/php-src/commit/7114314c5a96c362b95663f7e7c9184586721f58
11+
---
12+
apc_cache.h | 2 +-
13+
apc_iterator.c | 2 +-
14+
apc_iterator.h | 2 +-
15+
3 files changed, 3 insertions(+), 3 deletions(-)
16+
17+
diff --git a/apc_cache.h b/apc_cache.h
18+
index 36e81123..1db9b29c 100644
19+
--- a/apc_cache.h
20+
+++ b/apc_cache.h
21+
@@ -295,7 +295,7 @@ static inline void apc_cache_runlock(apc_cache_t *cache) {
22+
}
23+
24+
/* APC_ENTRY_SIZE takes into account the trailing key-string + terminating 0-byte */
25+
-#define APC_ENTRY_SIZE(key_len) (ZEND_MM_ALIGNED_SIZE(XtOffsetOf(apc_cache_entry_t, key.val) + key_len + 1))
26+
+#define APC_ENTRY_SIZE(key_len) (ZEND_MM_ALIGNED_SIZE(offsetof(apc_cache_entry_t, key.val) + key_len + 1))
27+
28+
/* ENTRYAT and ENTRYOF are used to convert between offsets and pointers to cache entries.
29+
* Both expect the presence of cache->header that points to the cache header in the
30+
diff --git a/apc_iterator.c b/apc_iterator.c
31+
index 535a9df7..cb7edc3b 100644
32+
--- a/apc_iterator.c
33+
+++ b/apc_iterator.c
34+
@@ -548,7 +548,7 @@ int apc_iterator_init(int module_number) {
35+
36+
apc_iterator_object_handlers.clone_obj = NULL;
37+
apc_iterator_object_handlers.free_obj = apc_iterator_free;
38+
- apc_iterator_object_handlers.offset = XtOffsetOf(apc_iterator_t, obj);
39+
+ apc_iterator_object_handlers.offset = offsetof(apc_iterator_t, obj);
40+
41+
return SUCCESS;
42+
}
43+
diff --git a/apc_iterator.h b/apc_iterator.h
44+
index d38a5a35..362dcb43 100644
45+
--- a/apc_iterator.h
46+
+++ b/apc_iterator.h
47+
@@ -69,7 +69,7 @@ typedef struct _apc_iterator_t {
48+
zend_object obj;
49+
} apc_iterator_t;
50+
51+
-#define apc_iterator_fetch_from(o) ((apc_iterator_t*)((char*)o - XtOffsetOf(apc_iterator_t, obj)))
52+
+#define apc_iterator_fetch_from(o) ((apc_iterator_t*)((char*)o - offsetof(apc_iterator_t, obj)))
53+
#define apc_iterator_fetch(z) apc_iterator_fetch_from(Z_OBJ_P(z))
54+
55+
typedef struct _apc_iterator_item_t {
56+
From d29e907791502af89a7996930f8dce5fd8efe4a1 Mon Sep 17 00:00:00 2001
57+
From: Andy Postnikov <apostnikov@gmail.com>
58+
Date: Fri, 10 Apr 2026 02:28:52 +0200
59+
Subject: [PATCH] Fix build against PHP 8.6 (EMPTY_SWITCH_DEFAULT_CASE removed)
60+
61+
Replace EMPTY_SWITCH_DEFAULT_CASE() with ZEND_UNREACHABLE() in
62+
apc_persist.c and add a fallback definition for PHP < 8.0 in apc.h,
63+
matching php-src debug/release behavior.
64+
65+
Modernize Windows CI to use php/php-windows-builder which handles
66+
packaging and artifact upload automatically. Add PHP 8.6 to Ubuntu CI.
67+
68+
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
69+
---
70+
.github/workflows/config.yml | 53 ++++++++----------------------------
71+
apc.h | 10 +++++++
72+
apc_persist.c | 6 ++--
73+
3 files changed, 26 insertions(+), 43 deletions(-)
74+
75+
diff --git a/apc.h b/apc.h
76+
index 6e725d04..8bbe3971 100644
77+
--- a/apc.h
78+
+++ b/apc.h
79+
@@ -67,6 +67,16 @@
80+
#include "php.h"
81+
#include "main/php_streams.h"
82+
83+
+/* ZEND_UNREACHABLE() was added in PHP 8.0. Provide fallback for PHP 7.x.
84+
+ * Remove this block when APCu drops support for PHP < 8.0. */
85+
+#if PHP_VERSION_ID < 80000
86+
+# if ZEND_DEBUG
87+
+# define ZEND_UNREACHABLE() do {ZEND_ASSERT(0); ZEND_ASSUME(0);} while (0)
88+
+# else
89+
+# define ZEND_UNREACHABLE() ZEND_ASSUME(0)
90+
+# endif
91+
+#endif
92+
+
93+
/* console display functions */
94+
PHP_APCU_API void apc_error(const char *format, ...) ZEND_ATTRIBUTE_FORMAT(printf, 1, 2);
95+
PHP_APCU_API void apc_warning(const char *format, ...) ZEND_ATTRIBUTE_FORMAT(printf, 1, 2);
96+
diff --git a/apc_persist.c b/apc_persist.c
97+
index e322b8d2..531695f3 100644
98+
--- a/apc_persist.c
99+
+++ b/apc_persist.c
100+
@@ -244,7 +244,8 @@ static zend_bool apc_persist_calc_zval(apc_persist_context_t *ctxt, const zval *
101+
case IS_RESOURCE:
102+
apc_warning("Cannot store resources in apcu cache");
103+
return 0;
104+
- EMPTY_SWITCH_DEFAULT_CASE()
105+
+ default:
106+
+ ZEND_UNREACHABLE();
107+
}
108+
}
109+
110+
@@ -450,7 +451,8 @@ static void apc_persist_copy_zval_impl(apc_persist_context_t *ctxt, zval *zv) {
111+
if (!ptr) ptr = apc_persist_copy_ref(ctxt, Z_REF_P(zv));
112+
ZVAL_REF(zv, ptr);
113+
return;
114+
- EMPTY_SWITCH_DEFAULT_CASE()
115+
+ default:
116+
+ ZEND_UNREACHABLE();
117+
}
118+
}
119+
120+
From 90899684be91c4f750512c2f840f487286ecb807 Mon Sep 17 00:00:00 2001
121+
From: Andy Postnikov <apostnikov@gmail.com>
122+
Date: Sat, 25 Jul 2026 20:10:30 +0200
123+
Subject: [PATCH] Simplify console output helpers to macros over
124+
php_error_docref
125+
126+
Replace the APC_PRINT_FUNCTION macro that generated four exported
127+
apc_error/apc_warning/apc_notice/apc_debug functions with thin variadic
128+
macros in apc.h that forward directly to php_error_docref(), and drop the
129+
generator block from apc.c entirely.
130+
131+
This also fixes the build against PHP 8.6-dev: php/php-src@0a12b3e8268
132+
removed the params argument from php_verror(), which the old
133+
APC_PRINT_FUNCTION body called. Forwarding to php_error_docref() instead
134+
sidesteps php_verror() altogether and works on all supported versions.
135+
136+
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
137+
---
138+
apc.c | 21 ---------------------
139+
apc.h | 14 ++++++++++----
140+
2 files changed, 10 insertions(+), 25 deletions(-)
141+
142+
diff --git a/apc.c b/apc.c
143+
index e2d039c..c6f4f16 100644
144+
--- a/apc.c
145+
+++ b/apc.c
146+
@@ -34,27 +34,6 @@
147+
#include "apc_globals.h"
148+
#include "php.h"
149+
150+
-/* console display functions */
151+
-#define APC_PRINT_FUNCTION(name, verbosity) \
152+
- void apc_##name(const char *format, ...) \
153+
- { \
154+
- va_list args; \
155+
- \
156+
- va_start(args, format); \
157+
- php_verror(NULL, "", verbosity, format, args); \
158+
- va_end(args); \
159+
- }
160+
-
161+
-APC_PRINT_FUNCTION(error, E_ERROR)
162+
-APC_PRINT_FUNCTION(warning, E_WARNING)
163+
-APC_PRINT_FUNCTION(notice, E_NOTICE)
164+
-
165+
-#ifdef APC_DEBUG
166+
-APC_PRINT_FUNCTION(debug, E_NOTICE)
167+
-#else
168+
-void apc_debug(const char *format, ...) {}
169+
-#endif
170+
-
171+
HashTable* apc_flip_hash(HashTable *hash) {
172+
zval data, *entry;
173+
HashTable *new_hash;
174+
diff --git a/apc.h b/apc.h
175+
index 8bbe397..cd9fa58 100644
176+
--- a/apc.h
177+
+++ b/apc.h
178+
@@ -78,10 +78,16 @@
179+
#endif
180+
181+
/* console display functions */
182+
-PHP_APCU_API void apc_error(const char *format, ...) ZEND_ATTRIBUTE_FORMAT(printf, 1, 2);
183+
-PHP_APCU_API void apc_warning(const char *format, ...) ZEND_ATTRIBUTE_FORMAT(printf, 1, 2);
184+
-PHP_APCU_API void apc_notice(const char *format, ...) ZEND_ATTRIBUTE_FORMAT(printf, 1, 2);
185+
-PHP_APCU_API void apc_debug(const char *format, ...) ZEND_ATTRIBUTE_FORMAT(printf, 1, 2);
186+
+#define apc_error(...) php_error_docref(NULL, E_ERROR, __VA_ARGS__)
187+
+#define apc_warning(...) php_error_docref(NULL, E_WARNING, __VA_ARGS__)
188+
+#define apc_notice(...) php_error_docref(NULL, E_NOTICE, __VA_ARGS__)
189+
+
190+
+#ifdef APC_DEBUG
191+
+# define apc_debug(...) php_error_docref(NULL, E_NOTICE, __VA_ARGS__)
192+
+#else
193+
+/* if (0) keeps compile-time format checking at zero runtime cost */
194+
+# define apc_debug(...) do { if (0) php_error_docref(NULL, E_NOTICE, __VA_ARGS__); } while (0)
195+
+#endif
196+
197+
/* apc_flip_hash flips keys and values for faster searching */
198+
PHP_APCU_API HashTable* apc_flip_hash(HashTable *hash);
199+
--
200+
2.55.0
201+
Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
From d4a6ded9ca6b3d7eec069de1891d03c5bc14c233 Mon Sep 17 00:00:00 2001
2+
From: Andy Postnikov <apostnikov@gmail.com>
3+
Date: Wed, 12 Aug 2026 03:27:27 +0200
4+
Subject: [PATCH 1/2] Fix build with PHP 8.6: unserialize_callback_func is a
5+
zend_string
6+
7+
php-src commit c82acefe470 (php 8.6.0beta1) converted the
8+
PG(unserialize_callback_func) global from char* to zend_string*.
9+
10+
Fixes #418
11+
---
12+
src/php7/igbinary.c | 19 +++++++++++++++++--
13+
1 file changed, 17 insertions(+), 2 deletions(-)
14+
15+
diff --git a/src/php7/igbinary.c b/src/php7/igbinary.c
16+
index 04048c6..9c2d77c 100644
17+
--- a/src/php7/igbinary.c
18+
+++ b/src/php7/igbinary.c
19+
@@ -3171,7 +3171,11 @@ zend_always_inline static int igbinary_unserialize_object(struct igbinary_unseri
20+
zval user_func;
21+
zval retval;
22+
zval args[1];
23+
+#if PHP_VERSION_ID >= 80600
24+
+ zend_string *user_func_name;
25+
+#else
26+
const char* user_func_name;
27+
+#endif
28+
29+
/* Try to find class directly */
30+
if (EXPECTED((ce = zend_lookup_class(class_name)) != NULL)) {
31+
@@ -3181,14 +3185,22 @@ zend_always_inline static int igbinary_unserialize_object(struct igbinary_unseri
32+
33+
user_func_name = PG(unserialize_callback_func);
34+
/* Check for unserialize callback */
35+
+#if PHP_VERSION_ID >= 80600
36+
+ if ((user_func_name == NULL) || (ZSTR_LEN(user_func_name) == 0)) {
37+
+#else
38+
if ((user_func_name == NULL) || (user_func_name[0] == '\0')) {
39+
+#endif
40+
incomplete_class = 1;
41+
ce = PHP_IC_ENTRY;
42+
break;
43+
}
44+
45+
/* Call unserialize callback */
46+
+#if PHP_VERSION_ID >= 80600
47+
+ ZVAL_STR(&user_func, zend_string_dup(user_func_name, false));
48+
+#else
49+
ZVAL_STRING(&user_func, user_func_name);
50+
+#endif
51+
ZVAL_STR(&args[0], class_name);
52+
if (call_user_function(CG(function_table), NULL, &user_func, &retval, 1, args) != SUCCESS) {
53+
php_error_docref(NULL, E_WARNING, "defined (%s) but not found", Z_STRVAL(user_func));
54+
@@ -3199,21 +3211,24 @@ zend_always_inline static int igbinary_unserialize_object(struct igbinary_unseri
55+
}
56+
/* FIXME: always safe? */
57+
zval_ptr_dtor(&retval);
58+
- zval_ptr_dtor_str(&user_func);
59+
60+
/* User function call may have raised an exception */
61+
if (EG(exception)) {
62+
zend_string_release_ex(class_name, 0);
63+
+ zval_ptr_dtor_str(&user_func);
64+
return 1;
65+
}
66+
67+
/* The callback function may have defined the class */
68+
ce = zend_lookup_class(class_name);
69+
if (!ce) {
70+
- php_error_docref(NULL, E_WARNING, "Function %s() hasn't defined the class it was called for", PG(unserialize_callback_func));
71+
+ /* Keep using our own copy of the name: the callback may have
72+
+ * changed unserialize_callback_func, releasing the ini string */
73+
+ php_error_docref(NULL, E_WARNING, "Function %s() hasn't defined the class it was called for", Z_STRVAL(user_func));
74+
incomplete_class = true;
75+
ce = PHP_IC_ENTRY;
76+
}
77+
+ zval_ptr_dtor_str(&user_func);
78+
} while (0);
79+
80+
if (IGBINARY_IS_NOT_UNSERIALIZABLE(ce)) {
81+
82+
From 48a3ef4f66986d7163d87bb72b218c845c8adeda Mon Sep 17 00:00:00 2001
83+
From: Andy Postnikov <apostnikov@gmail.com>
84+
Date: Wed, 12 Aug 2026 05:19:49 +0200
85+
Subject: [PATCH 2/2] Add test for unserialize_callback_func on PHP 8.6
86+
87+
Covers the two cases the change touches and the existing tests miss:
88+
89+
- An empty unserialize_callback_func. Every way of setting the ini
90+
(php.ini, -d, -c, ini_set) stores a non-NULL zero-length zend_string;
91+
only a total absence of ini leaves the global NULL. Without the length
92+
check the empty name is called, raising
93+
'Invalid callback , function "" not found'.
94+
- A callback that reassigns unserialize_callback_func while it runs. The
95+
warning has to name the callback that was actually called.
96+
---
97+
tests/igbinary_102.phpt | 38 ++++++++++++++++++++++++++++++++++++++
98+
1 file changed, 38 insertions(+)
99+
create mode 100644 tests/igbinary_102.phpt
100+
101+
diff --git a/tests/igbinary_102.phpt b/tests/igbinary_102.phpt
102+
new file mode 100644
103+
index 0000000..ec3f096
104+
--- /dev/null
105+
+++ b/tests/igbinary_102.phpt
106+
@@ -0,0 +1,38 @@
107+
+--TEST--
108+
+Object test, unserialize_callback_func (empty value, callback changing the setting)
109+
+--SKIPIF--
110+
+<?php if (PHP_VERSION_ID < 80600) echo "skip requires php >= 8.6\n"; ?>
111+
+--INI--
112+
+error_reporting=E_ALL
113+
+unserialize_callback_func=
114+
+--FILE--
115+
+<?php
116+
+if(!extension_loaded('igbinary')) {
117+
+ dl('igbinary.' . PHP_SHLIB_SUFFIX);
118+
+}
119+
+
120+
+// TODO undo workaround when #[AllowDynamicProperties] is added to __PHP_Incomplete_Class
121+
+error_reporting(E_ALL & ~E_DEPRECATED);
122+
+
123+
+// An empty unserialize_callback_func means "no callback", it must not be
124+
+// called as if it were a function name.
125+
+var_dump(ini_get('unserialize_callback_func'));
126+
+var_dump(get_class(igbinary_unserialize(pack('H*', '0000000217034f626a140211016106011101620602'))));
127+
+
128+
+// The callback is free to change unserialize_callback_func while it runs.
129+
+// The warning has to name the callback that was actually called.
130+
+function reassigning_autoload($classname) {
131+
+ echo "Called for $classname\n";
132+
+ ini_set('unserialize_callback_func', 'some_other_callback');
133+
+}
134+
+
135+
+ini_set('unserialize_callback_func', 'reassigning_autoload');
136+
+var_dump(get_class(igbinary_unserialize(pack('H*', '0000000217034f626b140211016106011101620602'))));
137+
+?>
138+
+--EXPECTF--
139+
+string(0) ""
140+
+string(22) "__PHP_Incomplete_Class"
141+
+Called for Obk
142+
+
143+
+Warning: igbinary_unserialize(): Function reassigning_autoload() hasn't defined the class it was called for in %sigbinary_102.php on line %d
144+
+string(22) "__PHP_Incomplete_Class"

0 commit comments

Comments
 (0)