Hi!

Lars Schultz wrote:

As you can see I boldly used the function reference_count(Object) even though it doesn't exist. This is exactly what I'd need to allow my concept to work.

Some time ago I created a patch to implement a ref_count() function which works the way you suggested. But I'm not sure if it's OK/complete... and I'm not sure if something like that is really needed in the core (and I'm definetly not the person to decide on that ;-)).

Anyway, I attatched a simple patch against current 5_2 branch to this mail, perhaps it helps.

Best regards
Andreas



Index: basic_functions.c
===================================================================
RCS file: /repository/php-src/ext/standard/basic_functions.c,v
retrieving revision 1.725.2.31.2.39
diff -u -r1.725.2.31.2.39 basic_functions.c
--- basic_functions.c   1 Jan 2007 09:36:08 -0000       1.725.2.31.2.39
+++ basic_functions.c   19 Jan 2007 17:04:39 -0000
@@ -3040,6 +3040,11 @@
 /* }}} */
 /* {{{ var.c */
 static
+ZEND_BEGIN_ARG_INFO(arginfo_ref_count, 0)
+       ZEND_ARG_INFO(0, var)
+ZEND_END_ARG_INFO()
+
+static
 ZEND_BEGIN_ARG_INFO_EX(arginfo_var_dump, 0, 0, 1)
        ZEND_ARG_INFO(0, var)
        ZEND_ARG_INFO(0, ...)
@@ -3384,6 +3389,7 @@
        PHP_FE(serialize,                                                       
                                                        arginfo_serialize)
        PHP_FE(unserialize,                                                     
                                                        arginfo_unserialize)
 
+       PHP_FE(ref_count,                                                       
                                                        arginfo_ref_count)
        PHP_FE(var_dump,                                                        
                                                        arginfo_var_dump)
        PHP_FE(var_export,                                                      
                                                        arginfo_var_export)
        PHP_FE(debug_zval_dump,                                                 
                                                arginfo_debug_zval_dump)
Index: php_var.h
===================================================================
RCS file: /repository/php-src/ext/standard/php_var.h,v
retrieving revision 1.30.2.1.2.5
diff -u -r1.30.2.1.2.5 php_var.h
--- php_var.h   1 Jan 2007 09:36:08 -0000       1.30.2.1.2.5
+++ php_var.h   19 Jan 2007 17:04:39 -0000
@@ -23,6 +23,7 @@
 
 #include "ext/standard/php_smart_str_public.h"
 
+PHP_FUNCTION(ref_count);
 PHP_FUNCTION(var_dump);
 PHP_FUNCTION(var_export);
 PHP_FUNCTION(debug_zval_dump);
Index: var.c
===================================================================
RCS file: /repository/php-src/ext/standard/var.c,v
retrieving revision 1.203.2.7.2.14
diff -u -r1.203.2.7.2.14 var.c
--- var.c       1 Jan 2007 09:36:09 -0000       1.203.2.7.2.14
+++ var.c       19 Jan 2007 17:04:39 -0000
@@ -39,6 +39,21 @@
 #define Z_REFCOUNT_PP(a) ((*a)->refcount)
 
 /* }}} */
+/* {{{ proto int ref_count(mixed var)
+   return the number of references pointing to a var */
+PHP_FUNCTION(ref_count)
+{
+       zval *var;
+       int cnt = 0;
+
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &var) == 
FAILURE) {
+               RETURN_NULL();
+       }
+
+       cnt = var->refcount;
+       RETURN_LONG (cnt);
+};
+/* }}} */
 /* {{{ php_var_dump */
 
 static int php_array_element_dump(zval **zv, int num_args, va_list args, 
zend_hash_key *hash_key)

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to