|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #66455 Missing function to determine refcount of variables directy
Submitted: 2014-01-10 08:43 UTC Modified: 2015-04-07 17:07 UTC
From: leuffen at continue dot de Assigned:
Status: Duplicate Package: Variables related
PHP Version: 5.5.8RC1 OS: Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: leuffen at continue dot de
New email:
PHP Version: OS:


 [2014-01-10 08:43 UTC] leuffen at continue dot de
While working on an Entity-Manager Class I noticed PHP has no function to determine the number of active references to a variable/object (like debug_zval_dump() does).

It would be great if PHP provided that feature in later versions.

Test script:
 * function to do the job:
function refcount ($var) {
    $zval = ob_get_clean();

    preg_match ("/refcount\\(([0-9]+)\\)/", $zval, $matches);
    return $matches[1];


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2014-08-15 03:42 UTC] ky dot patterson at adlinkr dot com
As I understand it, this cannot be done with a function.
debug_zval_dump() does not itself return accurate results.

The act of passing a variable to a function (by reference or by value) changes or replaces the variable's zval.
So the refcount you will get is inaccurate -- and not just "off by 1", because zend may copy the zval before it is passed to your function.

There are several other bugs that either ask for a refcount function, or ask for debug_zval_dump to be "fixed" to support pass-by-reference, and all of them are not workable AFAIK: Request for refcount function Add var_ref_count() Missing function to determine refcount of variables directy debug_zval_dump should be by ref

I *think* the solution is actually to add new language constructs, and I have opened a bug to discuss that:
 [2015-04-07 17:07 UTC]
-Status: Open +Status: Duplicate
 [2015-04-07 17:07 UTC]
Marking as duplicate, per ky's last comment.
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Mon Mar 01 13:01:24 2021 UTC