From:
Operating system: Any
PHP version: 5.3.3RC1
Package: Variables related
Bug Type: Feature/Change Request
Bug description:Add var_ref_count()
Description:
------------
It seems there is no easy way to know if an object/array/... is reference.
Looking at the source code of ext/standard/var.c it seems it may be not so
hard to add that function. As debug_zval_dump already outputs the reference
count, it would be better to obtain that value in order to determine if an
object is referenced or not. Maybe something like (I'm not C programmer):
PHPAPI void php_var_ref_count(zval **struc)
{
return Z_REFCOUNT_PP(struc);
}
Knowing the reference count may be helpful to:
- make copies of a structure without references
- remove variables that have more than 1 reference (safe remove)
- remove variables that are not referenced (unused values)
- prevent modifying a variable that is referenced
I believe there must be more applications but these are the ones I can
think of.
(background:
http://stackoverflow.com/questions/3148125/php-check-if-object-array-is-a-reference)
Test script:
---------------
<?php
$en = array("a" => "apple", "b" => "banana");
$es = array("a" => "manzana", "b" => "platano");
$dict = array(
"Eng" => $en,
"Esp" => $es,
"Non" => array("a" => "A", "b" => "B")
);
echo var_ref_count($dict["Eng"]);
echo " # ";
echo var_ref_count($dict["Non"]);
?>
Expected result:
----------------
2 # 1
Actual result:
--------------
None (inexistent)
--
Edit bug report at http://bugs.php.net/bug.php?id=52215&edit=1
--
Try a snapshot (PHP 5.2):
http://bugs.php.net/fix.php?id=52215&r=trysnapshot52
Try a snapshot (PHP 5.3):
http://bugs.php.net/fix.php?id=52215&r=trysnapshot53
Try a snapshot (trunk):
http://bugs.php.net/fix.php?id=52215&r=trysnapshottrunk
Fixed in SVN:
http://bugs.php.net/fix.php?id=52215&r=fixed
Fixed in SVN and need be documented:
http://bugs.php.net/fix.php?id=52215&r=needdocs
Fixed in release:
http://bugs.php.net/fix.php?id=52215&r=alreadyfixed
Need backtrace:
http://bugs.php.net/fix.php?id=52215&r=needtrace
Need Reproduce Script:
http://bugs.php.net/fix.php?id=52215&r=needscript
Try newer version:
http://bugs.php.net/fix.php?id=52215&r=oldversion
Not developer issue:
http://bugs.php.net/fix.php?id=52215&r=support
Expected behavior:
http://bugs.php.net/fix.php?id=52215&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=52215&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=52215&r=submittedtwice
register_globals:
http://bugs.php.net/fix.php?id=52215&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=52215&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=52215&r=dst
IIS Stability:
http://bugs.php.net/fix.php?id=52215&r=isapi
Install GNU Sed:
http://bugs.php.net/fix.php?id=52215&r=gnused
Floating point limitations:
http://bugs.php.net/fix.php?id=52215&r=float
No Zend Extensions:
http://bugs.php.net/fix.php?id=52215&r=nozend
MySQL Configuration Error:
http://bugs.php.net/fix.php?id=52215&r=mysqlcfg