Skip to content

Suppress deprecation notices when ext/dom properties are accessed by the get_debug_info handler #15530

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions ext/dom/document.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,7 @@ zend_result dom_document_encoding_read(dom_object *obj, zval *retval)

zend_result dom_document_actual_encoding_read(dom_object *obj, zval *retval)
{
zend_error(E_DEPRECATED, "Property DOMDocument::$actualEncoding is deprecated");
if (UNEXPECTED(EG(exception))) {
return FAILURE;
}
PHP_DOM_DEPRECATED_PROPERTY("Property DOMDocument::$actualEncoding is deprecated");

return dom_document_encoding_read(obj, retval);
}
Expand Down Expand Up @@ -419,10 +416,7 @@ Since: DOM Level 3
*/
zend_result dom_document_config_read(dom_object *obj, zval *retval)
{
zend_error(E_DEPRECATED, "Property DOMDocument::$config is deprecated");
if (UNEXPECTED(EG(exception))) {
return FAILURE;
}
PHP_DOM_DEPRECATED_PROPERTY("Property DOMDocument::$config is deprecated");

ZVAL_NULL(retval);
return SUCCESS;
Expand Down
15 changes: 3 additions & 12 deletions ext/dom/entity.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,7 @@ Since: DOM Level 3
*/
zend_result dom_entity_actual_encoding_read(dom_object *obj, zval *retval)
{
zend_error(E_DEPRECATED, "Property DOMEntity::$actualEncoding is deprecated");
if (UNEXPECTED(EG(exception))) {
return FAILURE;
}
PHP_DOM_DEPRECATED_PROPERTY("Property DOMEntity::$actualEncoding is deprecated");

ZVAL_NULL(retval);
return SUCCESS;
Expand All @@ -122,10 +119,7 @@ Since: DOM Level 3
*/
zend_result dom_entity_encoding_read(dom_object *obj, zval *retval)
{
zend_error(E_DEPRECATED, "Property DOMEntity::$encoding is deprecated");
if (UNEXPECTED(EG(exception))) {
return FAILURE;
}
PHP_DOM_DEPRECATED_PROPERTY("Property DOMEntity::$encoding is deprecated");

ZVAL_NULL(retval);
return SUCCESS;
Expand All @@ -140,10 +134,7 @@ Since: DOM Level 3
*/
zend_result dom_entity_version_read(dom_object *obj, zval *retval)
{
zend_error(E_DEPRECATED, "Property DOMEntity::$version is deprecated");
if (UNEXPECTED(EG(exception))) {
return FAILURE;
}
PHP_DOM_DEPRECATED_PROPERTY("Property DOMEntity::$version is deprecated");

ZVAL_NULL(retval);
return SUCCESS;
Expand Down
20 changes: 19 additions & 1 deletion ext/dom/php_dom.c
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,16 @@ static const libxml_doc_props default_doc_props = {
.classmap = NULL,
};

ZEND_DECLARE_MODULE_GLOBALS(dom)

static PHP_GINIT_FUNCTION(dom)
{
#if defined(COMPILE_DL_DOM) && defined(ZTS)
ZEND_TSRMLS_CACHE_UPDATE();
#endif
dom_globals->suppress_warnings = false;
}

/* {{{ dom_get_doc_props() */
dom_doc_propsptr dom_get_doc_props(php_libxml_ref_obj *document)
{
Expand Down Expand Up @@ -464,6 +474,8 @@ static HashTable* dom_get_debug_info_helper(zend_object *object, int *is_temp) /
return debug_info;
}

DOM_G(suppress_warnings) = true;

object_str = ZSTR_INIT_LITERAL("(object value omitted)", false);

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

zend_string_release_ex(object_str, false);

DOM_G(suppress_warnings) = false;

return debug_info;
}
/* }}} */
Expand Down Expand Up @@ -668,7 +682,11 @@ zend_module_entry dom_module_entry = { /* {{{ */
NULL,
PHP_MINFO(dom),
DOM_API_VERSION, /* Extension versionnumber */
STANDARD_MODULE_PROPERTIES
PHP_MODULE_GLOBALS(dom),
PHP_GINIT(dom),
NULL,
NULL,
STANDARD_MODULE_PROPERTIES_EX
};
/* }}} */

Expand Down
17 changes: 17 additions & 0 deletions ext/dom/php_dom.h
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,23 @@ static zend_always_inline const xmlChar *php_dom_get_content_or_empty(const xmlN
return node->content ? node->content : BAD_CAST "";
}

#define PHP_DOM_DEPRECATED_PROPERTY(message) do { \
if (EXPECTED(!DOM_G(suppress_warnings))) {\
zend_error(E_DEPRECATED, message); \
if (UNEXPECTED(EG(exception))) { \
return FAILURE; \
} \
} \
} while (0)

ZEND_BEGIN_MODULE_GLOBALS(dom)
bool suppress_warnings;
ZEND_END_MODULE_GLOBALS(dom)

ZEND_EXTERN_MODULE_GLOBALS(dom)

#define DOM_G(v) ZEND_MODULE_GLOBALS_ACCESSOR(dom, v)

PHP_MINIT_FUNCTION(dom);
PHP_MSHUTDOWN_FUNCTION(dom);
PHP_MINFO_FUNCTION(dom);
Expand Down
4 changes: 0 additions & 4 deletions ext/dom/tests/domobject_debug_handler.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ var_dump($d);
?>
--EXPECTF--
Deprecated: Creation of dynamic property DOMDocument::$dynamicProperty is deprecated in %s on line %d

Deprecated: Property DOMDocument::$actualEncoding is deprecated in %s on line %d

Deprecated: Property DOMDocument::$config is deprecated in %s on line %d
object(DOMDocument)#1 (41) {
["dynamicProperty"]=>
object(stdClass)#2 (0) {
Expand Down
Loading