|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2010-07-01 03:34 UTC] dev at alepe dot com
[2010-07-01 03:49 UTC] dtajchreber@php.net
[2010-07-01 13:44 UTC] derick@php.net
[2011-05-09 19:07 UTC] thegreatall at gmail dot com
[2012-09-23 22:09 UTC] chrisw at networkm dot co dot uk
[2014-08-15 03:39 UTC] ky dot patterson at adlinkr dot com
[2015-04-07 17:07 UTC] nikic@php.net
-Status: Open
+Status: Duplicate
[2015-04-07 17:07 UTC] nikic@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Nov 01 15:00:01 2025 UTC |
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)