]> granicus.if.org Git - php/commitdiff
Update for count_elements handler for overloaded objects.
authorWez Furlong <wez@php.net>
Tue, 4 May 2004 15:03:48 +0000 (15:03 +0000)
committerWez Furlong <wez@php.net>
Tue, 4 May 2004 15:03:48 +0000 (15:03 +0000)
ext/com_dotnet/com_handlers.c
ext/com_dotnet/com_saproxy.c
ext/simplexml/simplexml.c
ext/standard/array.c

index 9c80d9f4f955aae106746e963bc29a1ee653bb65..cfe15d43555f6e73e0f0bbb5e1dc3c29edeacfd0 100644 (file)
@@ -548,6 +548,25 @@ static int com_object_cast(zval *readobj, zval *writeobj, int type, int should_f
        return SUCCESS;
 }
 
+static int com_object_count(zval *object, long *count TSRMLS_DC)
+{
+       php_com_dotnet_object *obj;
+       LONG ubound = 0, lbound = 0;
+       
+       obj = CDNO_FETCH(object);
+       
+       if (!V_ISARRAY(&obj->v)) {
+               return FAILURE;
+       }
+
+       SafeArrayGetLBound(V_ARRAY(&obj->v), 1, &lbound);
+       SafeArrayGetUBound(V_ARRAY(&obj->v), 1, &ubound);
+
+       *count = ubound - lbound + 1;
+
+       return SUCCESS;
+}
+
 zend_object_handlers php_com_object_handlers = {
        ZEND_OBJECTS_STORE_HANDLERS,
        com_property_read,
@@ -568,7 +587,8 @@ zend_object_handlers php_com_object_handlers = {
        com_class_entry_get,
        com_class_name_get,
        com_objects_compare,
-       com_object_cast
+       com_object_cast,
+       com_object_count
 };
 
 void php_com_object_enable_event_sink(php_com_dotnet_object *obj, int enable TSRMLS_DC)
index 85d9b978a543aa6b463943e89e86c85648971d78..1dfbad5a1e8c63b74faf447db077a214baf29d6e 100644 (file)
@@ -362,6 +362,23 @@ static int saproxy_object_cast(zval *readobj, zval *writeobj, int type, int shou
        return FAILURE;
 }
 
+static int saproxy_count_elements(zval *object, long *count TSRMLS_DC)
+{
+       php_com_saproxy *proxy = SA_FETCH(object);
+       LONG ubound, lbound;
+       
+       if (!V_ISARRAY(&proxy->obj->v)) {
+               return FAILURE;
+       }
+
+       SafeArrayGetLBound(V_ARRAY(&proxy->obj->v), proxy->dimensions, &lbound);
+       SafeArrayGetUBound(V_ARRAY(&proxy->obj->v), proxy->dimensions, &ubound);
+
+       *count = ubound - lbound + 1;
+
+       return SUCCESS;
+}
+
 zend_object_handlers php_com_saproxy_handlers = {
        ZEND_OBJECTS_STORE_HANDLERS,
        saproxy_property_read,
@@ -382,7 +399,8 @@ zend_object_handlers php_com_saproxy_handlers = {
        saproxy_class_entry_get,
        saproxy_class_name_get,
        saproxy_objects_compare,
-       saproxy_object_cast
+       saproxy_object_cast,
+       saproxy_count_elements
 };
 
 static void saproxy_free_storage(void *object TSRMLS_DC)
index 968e528a755a5a234b7d573584c333986c60cab2..b2af53d210183ec680c8855c9a2d7f1453985103 100644 (file)
@@ -1077,7 +1077,8 @@ static zend_object_handlers sxe_object_handlers = {
        NULL, /* zend_get_std_object_handlers()->get_class_entry,*/
        NULL, /* zend_get_std_object_handlers()->get_class_name,*/
        sxe_objects_compare,
-       sxe_object_cast
+       sxe_object_cast,
+       NULL
 };
 
 /* {{{ sxe_object_clone()
index 539848322e5990ae3918e4127d6370b3085939a5..0100d02cd3c5bb7c4e38ad18209fe3df2cd83456 100644 (file)
@@ -290,6 +290,13 @@ PHP_FUNCTION(count)
                case IS_ARRAY:
                        RETURN_LONG (php_count_recursive (array, mode TSRMLS_CC));
                        break;
+               case IS_OBJECT:
+                       if (Z_OBJ_HT(*array)->count_elements) {
+                               RETVAL_LONG(1);
+                               if (SUCCESS == Z_OBJ_HT(*array)->count_elements(array, &Z_LVAL_P(return_value) TSRMLS_CC)) {
+                                       return;
+                               }
+                       }
                default:
                        RETURN_LONG(1);
                        break;