Last active
August 29, 2015 14:17
-
-
Save pjdietz/0f71a3aab9b37e589500 to your computer and use it in GitHub Desktop.
Return the number of references for a variable's zval
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Return the number of references for a variable's zval | |
* | |
* @param mixed $var Variable to inspect | |
* @return int Number of references according to debug_zval_dump | |
*/ | |
function refCount($var) | |
{ | |
ob_start(); | |
debug_zval_dump($var); | |
$dump = ob_get_clean(); | |
if (preg_match('~refcount\(([\d]+)\)~', $dump, $matches)) { | |
$refcount = $matches[1]; | |
return --$refcount; // Don't count the reference to this function | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment