Skip to content

Commit 7e45e57

Browse files
authored
Suppress deprecation notices when ext/dom properties are accessed by the get_debug_info handler (php#15530)
1 parent 793f632 commit 7e45e57

File tree

5 files changed

+41
-25
lines changed

5 files changed

+41
-25
lines changed

ext/dom/document.c

+2-8
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,7 @@ zend_result dom_document_encoding_read(dom_object *obj, zval *retval)
107107

108108
zend_result dom_document_actual_encoding_read(dom_object *obj, zval *retval)
109109
{
110-
zend_error(E_DEPRECATED, "Property DOMDocument::$actualEncoding is deprecated");
111-
if (UNEXPECTED(EG(exception))) {
112-
return FAILURE;
113-
}
110+
PHP_DOM_DEPRECATED_PROPERTY("Property DOMDocument::$actualEncoding is deprecated");
114111

115112
return dom_document_encoding_read(obj, retval);
116113
}
@@ -419,10 +416,7 @@ Since: DOM Level 3
419416
*/
420417
zend_result dom_document_config_read(dom_object *obj, zval *retval)
421418
{
422-
zend_error(E_DEPRECATED, "Property DOMDocument::$config is deprecated");
423-
if (UNEXPECTED(EG(exception))) {
424-
return FAILURE;
425-
}
419+
PHP_DOM_DEPRECATED_PROPERTY("Property DOMDocument::$config is deprecated");
426420

427421
ZVAL_NULL(retval);
428422
return SUCCESS;

ext/dom/entity.c

+3-12
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,7 @@ Since: DOM Level 3
104104
*/
105105
zend_result dom_entity_actual_encoding_read(dom_object *obj, zval *retval)
106106
{
107-
zend_error(E_DEPRECATED, "Property DOMEntity::$actualEncoding is deprecated");
108-
if (UNEXPECTED(EG(exception))) {
109-
return FAILURE;
110-
}
107+
PHP_DOM_DEPRECATED_PROPERTY("Property DOMEntity::$actualEncoding is deprecated");
111108

112109
ZVAL_NULL(retval);
113110
return SUCCESS;
@@ -122,10 +119,7 @@ Since: DOM Level 3
122119
*/
123120
zend_result dom_entity_encoding_read(dom_object *obj, zval *retval)
124121
{
125-
zend_error(E_DEPRECATED, "Property DOMEntity::$encoding is deprecated");
126-
if (UNEXPECTED(EG(exception))) {
127-
return FAILURE;
128-
}
122+
PHP_DOM_DEPRECATED_PROPERTY("Property DOMEntity::$encoding is deprecated");
129123

130124
ZVAL_NULL(retval);
131125
return SUCCESS;
@@ -140,10 +134,7 @@ Since: DOM Level 3
140134
*/
141135
zend_result dom_entity_version_read(dom_object *obj, zval *retval)
142136
{
143-
zend_error(E_DEPRECATED, "Property DOMEntity::$version is deprecated");
144-
if (UNEXPECTED(EG(exception))) {
145-
return FAILURE;
146-
}
137+
PHP_DOM_DEPRECATED_PROPERTY("Property DOMEntity::$version is deprecated");
147138

148139
ZVAL_NULL(retval);
149140
return SUCCESS;

ext/dom/php_dom.c

+19-1
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,16 @@ static const libxml_doc_props default_doc_props = {
203203
.classmap = NULL,
204204
};
205205

206+
ZEND_DECLARE_MODULE_GLOBALS(dom)
207+
208+
static PHP_GINIT_FUNCTION(dom)
209+
{
210+
#if defined(COMPILE_DL_DOM) && defined(ZTS)
211+
ZEND_TSRMLS_CACHE_UPDATE();
212+
#endif
213+
dom_globals->suppress_warnings = false;
214+
}
215+
206216
/* {{{ dom_get_doc_props() */
207217
dom_doc_propsptr dom_get_doc_props(php_libxml_ref_obj *document)
208218
{
@@ -464,6 +474,8 @@ static HashTable* dom_get_debug_info_helper(zend_object *object, int *is_temp) /
464474
return debug_info;
465475
}
466476

477+
DOM_G(suppress_warnings) = true;
478+
467479
object_str = ZSTR_INIT_LITERAL("(object value omitted)", false);
468480

469481
ZEND_HASH_MAP_FOREACH_STR_KEY_PTR(prop_handlers, string_key, entry) {
@@ -486,6 +498,8 @@ static HashTable* dom_get_debug_info_helper(zend_object *object, int *is_temp) /
486498

487499
zend_string_release_ex(object_str, false);
488500

501+
DOM_G(suppress_warnings) = false;
502+
489503
return debug_info;
490504
}
491505
/* }}} */
@@ -668,7 +682,11 @@ zend_module_entry dom_module_entry = { /* {{{ */
668682
NULL,
669683
PHP_MINFO(dom),
670684
DOM_API_VERSION, /* Extension versionnumber */
671-
STANDARD_MODULE_PROPERTIES
685+
PHP_MODULE_GLOBALS(dom),
686+
PHP_GINIT(dom),
687+
NULL,
688+
NULL,
689+
STANDARD_MODULE_PROPERTIES_EX
672690
};
673691
/* }}} */
674692

ext/dom/php_dom.h

+17
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,23 @@ static zend_always_inline const xmlChar *php_dom_get_content_or_empty(const xmlN
300300
return node->content ? node->content : BAD_CAST "";
301301
}
302302

303+
#define PHP_DOM_DEPRECATED_PROPERTY(message) do { \
304+
if (EXPECTED(!DOM_G(suppress_warnings))) {\
305+
zend_error(E_DEPRECATED, message); \
306+
if (UNEXPECTED(EG(exception))) { \
307+
return FAILURE; \
308+
} \
309+
} \
310+
} while (0)
311+
312+
ZEND_BEGIN_MODULE_GLOBALS(dom)
313+
bool suppress_warnings;
314+
ZEND_END_MODULE_GLOBALS(dom)
315+
316+
ZEND_EXTERN_MODULE_GLOBALS(dom)
317+
318+
#define DOM_G(v) ZEND_MODULE_GLOBALS_ACCESSOR(dom, v)
319+
303320
PHP_MINIT_FUNCTION(dom);
304321
PHP_MSHUTDOWN_FUNCTION(dom);
305322
PHP_MINFO_FUNCTION(dom);

ext/dom/tests/domobject_debug_handler.phpt

-4
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,6 @@ var_dump($d);
1616
?>
1717
--EXPECTF--
1818
Deprecated: Creation of dynamic property DOMDocument::$dynamicProperty is deprecated in %s on line %d
19-
20-
Deprecated: Property DOMDocument::$actualEncoding is deprecated in %s on line %d
21-
22-
Deprecated: Property DOMDocument::$config is deprecated in %s on line %d
2319
object(DOMDocument)#1 (41) {
2420
["dynamicProperty"]=>
2521
object(stdClass)#2 (0) {

0 commit comments

Comments
 (0)