Hi all,

I would like to propose we formally deprecate the function debug_zval_dump and 
remove it in PHP 9.0.

This function is mostly similar to var_dump, with the additional ability to 
output the refcount of a variable. This has always been hard to interpret, but 
is now so complex as to be effectively useless:

- Because it is implemented as a function taking a parameter in the normal way, 
the refcount has been modified by the time it is displayed. Depending on the 
value passed, this may include reference separation; in older versions of PHP, 
it was possible to affect this directly by forcing a pass-by-reference. The 
manual still discusses this, but it hasn't been possible since PHP 5.4. [1]
- Since PHP 7, some types don't have a refcount at all, and references are 
represented by additional levels of zval. Without completely changing the 
output format, this information is impossible to convey accurately.
- Optimisations affect the refcount in increasingly non-obvious ways. For 
instance, an array defined literally in the source code has an extra counted 
reference compared to one which has been modified at runtime. [2]

Since this is a rather specialised piece of debugging information, not useful 
to the average user, I think it should be left to dedicated debugging tools. 
XDebug includes an equivalent function that takes a name and looks it up in the 
symbol table, avoiding some of the worst issues [3]. I'm not familiar with 
PHPDBG, and it doesn't seem to have much documentation, but I assume it would 
be able to display this as well.

I notice there's a draft for an omnibus "deprecations for PHP 8.1" RFC [4]. 
Should I add this there, or raise a separate RFC?

Refs:
1: https://www.php.net/debug-zval-dump
2: https://3v4l.org/DVi3f
3: https://xdebug.org/docs/all_functions#xdebug_debug_zval
4: https://wiki.php.net/rfc/deprecations_php_8_1

Regards,
-- 
Rowan Tommins
[IMSoP]

Reply via email to