Req #66455 [Opn->Dup]: Missing function to determine refcount of variables directy
Edit report at https://bugs.php.net/bug.php?id=66455&edit=1
ID: 66455
Updated by: nikic@php.net
Reported by: leuffen at continue dot de
Summary: Missing function to determine refcount of variables
directy
-Status: Open
+Status: Duplicate
Type: Feature/Change Request
Package: Variables related
Operating System: Linux
PHP Version: 5.5.8RC1
Block user comment: N
Private report: N
New Comment:
Marking as duplicate, per ky's last comment.
Previous Comments:
------------------------------------------------------------------------
[2014-08-15 03:42:31] 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:
https://bugs.php.net/bug.php?id=40011 Request
for refcount function
https://bugs.php.net/bug.php?id=52215 Add
var_ref_count()
https://bugs.php.net/bug.php?id=66455 Missing
function to determine refcount of variables directy
https://bugs.php.net/bug.php?id=53895
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:
https://bugs.php.net/bug.php?id=67847
------------------------------------------------------------------------
[2014-01-10 08:43:32] leuffen at continue dot de
Description:
------------
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) {
ob_start();
debug_zval_dump($var);
$zval = ob_get_clean();
preg_match ("/refcount\\(([0-9]+)\\)/", $zval, $matches);
return $matches[1];
}
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=66455&edit=1
Thread (3 messages)