static HashTable *curl_get_gc(zend_object *object, zval **table, int *n);
static zend_function *curl_get_constructor(zend_object *object);
static zend_object *curl_clone_obj(zend_object *object);
+static int curl_cast_object(zend_object *obj, zval *result, int type);
php_curl *init_curl_handle_into_zval(zval *curl);
static inline int build_mime_structure_from_hash(php_curl *ch, zval *zpostfields);
curl_object_handlers.get_gc = curl_get_gc;
curl_object_handlers.get_constructor = curl_get_constructor;
curl_object_handlers.clone_obj = curl_clone_obj;
+ curl_object_handlers.cast_object = curl_cast_object;
curl_multi_register_class(class_CurlMultiHandle_methods);
curl_share_register_class(class_CurlShareHandle_methods);
return zend_std_get_properties(object);
}
+static int curl_cast_object(zend_object *obj, zval *result, int type)
+{
+ if (type == IS_LONG) {
+ /* For better backward compatibility, make (int) $curl_handle return the object ID,
+ * similar to how it previously returned the resource ID. */
+ ZVAL_LONG(result, obj->handle);
+ return SUCCESS;
+ }
+
+ return zend_std_cast_object_tostring(obj, result, type);
+}
+
/* {{{ PHP_MSHUTDOWN_FUNCTION
*/
PHP_MSHUTDOWN_FUNCTION(curl)
--- /dev/null
+--TEST--
+Casting CurlHandle to int returns object ID
+--FILE--
+<?php
+
+$handle1 = curl_init();
+var_dump((int) $handle1);
+$handle2 = curl_init();
+var_dump((int) $handle2);
+
+// NB: Unlike resource IDs, object IDs are reused.
+unset($handle2);
+$handle3 = curl_init();
+var_dump((int) $handle3);
+
+?>
+--EXPECT--
+int(1)
+int(2)
+int(2)