From 34667bbc40edbd282f1c44f0b76cc9ca769390bd Mon Sep 17 00:00:00 2001 From: Levi Morrison Date: Thu, 10 Sep 2026 15:40:34 -0600 Subject: [PATCH] fix: preserve PHP 7.1 ZTS property names --- ext/compatibility.h | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/ext/compatibility.h b/ext/compatibility.h index 17ddd59c7b8..39e29cc44cf 100644 --- a/ext/compatibility.h +++ b/ext/compatibility.h @@ -389,7 +389,29 @@ static inline const zend_function *dd_zend_get_closure_method_def(zend_object *o #define ZEND_ARG_OBJ_INFO_WITH_DEFAULT_VALUE(pass_by_ref, name, classname, allow_null, default_value) ZEND_ARG_OBJ_INFO(pass_by_ref, name, classname, allow_null) #define ZEND_ARG_OBJ_TYPE_MASK(pass_by_ref, name, class_name, type_mask, default_value) ZEND_ARG_INFO(pass_by_ref, name) -#define zend_declare_typed_property(ce, name, default, visibility, doc_comment, type) zend_declare_property_ex(ce, name, default, visibility, doc_comment); (void)type + +#if PHP_VERSION_ID >= 70100 && PHP_VERSION_ID < 70200 && defined(ZTS) +/* PHP 7.1 ZTS destroys its process-wide interned strings before destroying the + * main thread's copied class table. A typed-property stub may pass ZSTR_KNOWN() + * here, leaving the copied property info pointing at an already-freed string + * during tsrm_shutdown(). Store a regular persistent string instead. */ +static inline int datadog_declare_property_ex(zend_class_entry *ce, zend_string *name, zval *property, + int access_type, zend_string *doc_comment) { + if (!ZSTR_IS_INTERNED(name)) { + return zend_declare_property_ex(ce, name, property, access_type, doc_comment); + } + + zend_string *persistent_name = zend_string_init(ZSTR_VAL(name), ZSTR_LEN(name), true); + int result = zend_declare_property_ex(ce, persistent_name, property, access_type, doc_comment); + zend_string_release_ex(persistent_name, true); + return result; +} +#define zend_declare_typed_property(ce, name, default, visibility, doc_comment, type) \ + datadog_declare_property_ex(ce, name, default, visibility, doc_comment); (void)type +#else +#define zend_declare_typed_property(ce, name, default, visibility, doc_comment, type) \ + zend_declare_property_ex(ce, name, default, visibility, doc_comment); (void)type +#endif #define ZEND_TYPE_INIT_MASK(type) NULL #define ZEND_TYPE_INIT_CLASS(class_name, allow_null, extra_flags) NULL; zend_string_release(class_name)