Alex Rivera | Logout

Why doesn't var_dump work with DOMDocument objects, while print($dom->saveHTML()) does?

Asked 2011-01-23T19:55:41.083
18

Why doesn't var_dump work with DOMDocument objects, while print($dom->saveHTML()) produces output?

Edit
Report

2 Answers

9

Update: As of PHP 5.4.1 you can finally var_dump DOM objects. See https://gist.github.com/2499678


It's a bug:

answered 2011-01-23T20:53:45.390
6

It has nothing to do with any interfaces and in fact is very simple. var_dump shows only those class properties that have been declared by their developers by calling such C-functions as

ZEND_API int zend_declare_property(...)
ZEND_API int zend_declare_property_null(...)
ZEND_API int zend_declare_property_bool(...)
ZEND_API int zend_declare_property_long(...)
ZEND_API int zend_declare_property_double(...)
ZEND_API int zend_declare_property_string(...)
ZEND_API int zend_declare_property_stringl(...)

For instance, the properties of the class Exception are declared in the file Zend/zend_exceptions.c like this

   zend_declare_property_string(default_exception_ce, "message", sizeof("message")-1, "", ZEND_ACC_PROTECTED TSRMLS_CC);
   zend_declare_property_string(default_exception_ce, "string", sizeof("string")-1, "", ZEND_ACC_PRIVATE TSRMLS_CC);
   zend_declare_property_long(default_exception_ce, "code", sizeof("code")-1, 0, ZEND_ACC_PROTECTED TSRMLS_CC);
   zend_declare_property_null(default_exception_ce, "file", sizeof("file")-1, ZEND_ACC_PROTECTED TSRMLS_CC);
   zend_declare_property_null(default_exception_ce, "line", sizeof("line")-1, ZEND_ACC_PROTECTED TSRMLS_CC);
   zend_declare_property_null(default_exception_ce, "trace", sizeof("trace")-1, ZEND_ACC_PRIVATE TSRMLS_CC);
   zend_declare_property_null(default_exception_ce, "previous", sizeof("previous")-1, ZEND_ACC_PRIVATE TSRMLS_CC);

All these functions then call

ZEND_API int zend_declare_property_ex(zend_class_entry *ce, const char *name, ...

which updates the property list. Then comes the var_dump in ext/standard/var.c and looks them up by calling php_object_property_dump which enumerates them through the same property list. You see the intentionally exposed inner structure.

The developers of the DOM extension just have ch

answered 2011-01-23T20:11:40.613

Your Answer