- ob_get_clean: documentation ( source)
- ob_start: documentation ( source)
- preg_match: documentation ( source)
- debug_zval_dump: documentation ( source)
<?php
function countRefs($var) {
ob_start();
debug_zval_dump($var);
preg_match('~refcount\((\d+)\)~', ob_get_clean(), $matches);
return $matches[1] - 4;
}
$a = 0;
$a = &$a;
echo countRefs($a);
$a = &$a;
echo countRefs($a);