Skip to content

Commit 7639a2c

Browse files
committed
fix #137
account for PHP-7.4's zend_object_handlers.get_properties_for handler
1 parent 26171e6 commit 7639a2c

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

msgpack_pack.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,14 +197,26 @@ static inline void msgpack_serialize_array(smart_str *buf, zval *val, HashTable
197197
HashTable *ht;
198198
zend_bool hash = 1;
199199
zend_bool is_ref = 0;
200+
#if PHP_VERSION_ID >= 70400
201+
zend_bool free_ht = 0;
202+
#endif
200203

201204
if (UNEXPECTED(Z_TYPE_P(val) == IS_REFERENCE)) {
202205
is_ref = 1;
203206
val = Z_REFVAL_P(val);
204207
}
205208

206209
if (object) {
210+
#if PHP_VERSION_ID >= 70400
211+
if (Z_OBJ_HANDLER_P(val, get_properties_for)) {
212+
ht = Z_OBJ_HANDLER_P(val, get_properties_for)(val, ZEND_PROP_PURPOSE_ARRAY_CAST);
213+
free_ht = 1;
214+
} else {
215+
ht = Z_OBJPROP_P(val);
216+
}
217+
#else
207218
ht = Z_OBJPROP_P(val);
219+
#endif
208220
} else {
209221
ZEND_ASSERT(Z_TYPE_P(val) == IS_ARRAY);
210222
ht = Z_ARRVAL_P(val);
@@ -372,6 +384,11 @@ static inline void msgpack_serialize_array(smart_str *buf, zval *val, HashTable
372384
}
373385
}
374386
}
387+
#if PHP_VERSION_ID >= 70400
388+
if (free_ht && ht) {
389+
zend_array_destroy(ht);
390+
}
391+
#endif
375392
}
376393
/* }}} */
377394

0 commit comments

Comments
 (0)