Skip to content

Stdlib: debug_zval_dump() reference refcount on aliased array slots (#4709) - #17257

Merged
PurHur merged 1 commit into
masterfrom
agent/issue-4709-debug-zval-refcount
Jul 7, 2026
Merged

PurHur merged 1 commit into
masterfrom
agent/issue-4709-debug-zval-refcount

Conversation

@PurHur

@PurHur PurHur commented Jul 7, 2026

Copy link
Copy Markdown
Owner

Summary

Root cause

VM stores by-ref values in the array bucket directly; only external variables use TYPE_INDIRECT. debug_zval_dump() previously resolved values and never detected shared storage.

php-src reference

  • ext/standard/php_debug.c — PHP_FUNCTION(debug_zval_dump)
  • Zend/zend_variables.c — zend_debug_zval() refcount formatting

PHP implementation

  • ext/standard/VmDebugZval.php — dump + alias counting via VM::visitStrongRefRoots()
  • ext/standard/debug_zval_dump.php — thin builtin delegating to VmDebugZval

Verification

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php test/repro-maintainer/debug_zval_dump_refcount.php
php bin/vm.php test/repro-maintainer/debug_zval_dump_refcount.php
# diff empty — VM matches Zend
php test/repro-maintainer/debug_zval_dump_refcount.php | diff -u - <(php bin/vm.php test/repro-maintainer/debug_zval_dump_refcount.php)
vendor/bin/phpunit --filter debug_zval_dump_refcount test/compliance/
'

Output:

array(2) refcount(2){
  [0]=>
  reference refcount(2) {
    int(1)
  }
  [1]=>
  int(2)
}
int(1)
MATCH
OK (3 tests, 3 assertions)

Closes #4709

Made with Cursor

…4709)

Extract VmDebugZval SSOT and render reference refcount(N) blocks when
array elements are shared via by-ref aliases, matching Zend/php-src output.

Co-authored-by: Cursor <cursoragent@cursor.com>
@PurHur
PurHur merged commit 2b2a668 into master Jul 7, 2026
@PurHur
PurHur deleted the agent/issue-4709-debug-zval-refcount branch July 7, 2026 16:51
PurHur added a commit that referenced this pull request Jul 7, 2026
…tHook (#17265) (#17266)

Regenerate docs/bootstrap-inventory.md so bootstrap-inventory.php --check
is green after #17257/#17258 added vm.php-path spine files.

Co-authored-by: PurHur <PurHur@users.noreply.github.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Stdlib: debug_zval_dump() — zval introspection for debugging (ext/standard/php_debug.c parity)

1 participant