diff --git a/apc_persist.c b/apc_persist.c
index 0f8ac539..4e4b3cef 100644
--- a/apc_persist.c
+++ b/apc_persist.c
@@ -565,11 +565,15 @@ static zend_array *apc_unpersist_ht(
apc_unpersist_add_already_copied(ctxt, orig_ht, ht);
memcpy(ht, orig_ht, sizeof(HashTable));
GC_TYPE_INFO(ht) = GC_ARRAY;
-
+#if PHP_VERSION_ID >= 70300
+ /* Caller used ZVAL_EMPTY_ARRAY and set different zval flags instead */
+ ZEND_ASSERT(ht->nNumOfElements > 0 && ht->nNumUsed > 0);
+#else
if (ht->nNumUsed == 0) {
HT_SET_DATA_ADDR(ht, &uninitialized_bucket);
return ht;
}
+#endif
HT_SET_DATA_ADDR(ht, emalloc(HT_SIZE(ht)));
memcpy(HT_GET_DATA_ADDR(ht), HT_GET_DATA_ADDR(orig_ht), HT_HASH_SIZE(ht->nTableMask));
@@ -628,6 +632,12 @@ static void apc_unpersist_zval_impl(apc_unpersist_context_t *ctxt, zval *zv) {
Z_REF_P(zv) = apc_unpersist_ref(ctxt, Z_REF_P(zv));
return;
case IS_ARRAY:
+#if PHP_VERSION_ID >= 70300
+ if (Z_ARR_P(zv)->nNumOfElements == 0) {
+ ZVAL_EMPTY_ARRAY(zv); /* #323 */
+ return;
+ }
+#endif
Z_ARR_P(zv) = apc_unpersist_ht(ctxt, Z_ARR_P(zv));
return;
default:
diff --git a/package.xml b/package.xml
index 0529153e..8f2398d2 100644
--- a/package.xml
+++ b/package.xml
@@ -82,6 +82,7 @@
+
@@ -718,7 +719,7 @@ and unpersisting values.
- Bring back spinlocks, various issues (Joe)
- Fixed symbol clashing, windows debug mode, again (Anatol)
- apcu_key_info / apc_cache_stat functions (Joe)
-
+
diff --git a/tests/apcu_fetch_empty_array_reference.phpt b/tests/apcu_fetch_empty_array_reference.phpt
new file mode 100644
index 00000000..7ed0b134
--- /dev/null
+++ b/tests/apcu_fetch_empty_array_reference.phpt
@@ -0,0 +1,55 @@
+--TEST--
+apcu_fetch should work for multiple reference groups
+--SKIPIF--
+
+--INI--
+apc.enabled=1
+apc.enable_cli=1
+--FILE--
+
+--EXPECT--
+array(4) {
+ [0]=>
+ &array(0) {
+ }
+ [1]=>
+ &array(0) {
+ }
+ [2]=>
+ &array(0) {
+ }
+ [3]=>
+ &array(0) {
+ }
+}
+array(4) {
+ [0]=>
+ &array(1) {
+ [1]=>
+ object(stdClass)#1 (0) {
+ }
+ }
+ [1]=>
+ &array(1) {
+ [1]=>
+ object(stdClass)#1 (0) {
+ }
+ }
+ [2]=>
+ &array(0) {
+ }
+ [3]=>
+ &array(0) {
+ }
+}