Skip to content

Convert CURL resources to objects #5402

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 12 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions UPGRADING
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,21 @@ PHP 8.0 UPGRADE NOTES

- CURL:
. The CURL extension now requires at least libcurl 7.29.0.
. curl_init() will now return a Curl object rather than a resource.
Return value checks using is_resource() should be replaced with
checks for `false`. The curl_close() function no longer has an effect,
instead the Curl instance is automatically destroyed if it is no longer
referenced.
. curl_multi_init() will now return a CurlMulti object rather than a resource.
Return value checks using is_resource() should be replaced with
checks for `false`. The curl_multi_close() function no longer has an effect,
instead the CurlMulti instance is automatically destroyed if it is no longer
referenced.
. curl_share_init() will now return a CurlShare object rather than a resource.
Return value checks using is_resource() should be replaced with
checks for `false`. The curl_share_close() function no longer has an effect,
instead the CurlShare instance is automatically destroyed if it is no longer
referenced.

- Enchant:
. The enchant extension now uses libenchant-2 by default when available.
Expand Down
122 changes: 42 additions & 80 deletions ext/curl/curl.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,120 +2,82 @@

/** @generate-function-entries */

/** @param resource $handle */
function curl_close($handle): void {}
final class CurlHandle
{
}

/**
* @param resource $handle
* @return resource|false
*/
function curl_copy_handle($handle) {}
final class CurlMultiHandle
{
}

/** @param resource $handle */
function curl_errno($handle): int {}
final class CurlShareHandle
{
}

/** @param resource $handle */
function curl_error($handle): string {}
function curl_close(CurlHandle $handle): void {}

function curl_copy_handle(CurlHandle $handle): CurlHandle|false {}

function curl_errno(CurlHandle $handle): int {}

function curl_error(CurlHandle $handle): string {}

#if LIBCURL_VERSION_NUM >= 0x070f04 /* 7.15.4 */
/** @param resource $handle */
function curl_escape($handle, string $string): string|false {}
function curl_escape(CurlHandle $handle, string $string): string|false {}

/** @param resource $handle */
function curl_unescape($handle, string $string): string|false {}
function curl_unescape(CurlHandle $handle, string $string): string|false {}

/**
* @param resource $multi_handle
* @param mixed $value
*/
function curl_multi_setopt($multi_handle, int $option, $value): bool {}
function curl_multi_setopt(CurlMultiHandle $multi_handle, int $option, mixed $value): bool {}

#endif

/** @param resource $handle */
function curl_exec($handle): string|bool {}
function curl_exec(CurlHandle $handle): string|bool {}

function curl_file_create(
string $filename,
string $mimetype = UNKNOWN,
string $postname = UNKNOWN
): CURLFile {}
function curl_file_create(string $filename, string $mimetype = UNKNOWN, string $postname = UNKNOWN): CURLFile {}

/**
* @param resource $handle
* @return mixed
*/
function curl_getinfo($handle, int $option = UNKNOWN) {}
function curl_getinfo(CurlHandle $handle, int $option = UNKNOWN): mixed {}

/**
* @param resource $handle
* @return resource|false
*/
function curl_init(string $url = UNKNOWN) {}
function curl_init(string $url = UNKNOWN): CurlHandle|false {}

/**
* @param resource $multi_handle
* @param resource $handle
*/
function curl_multi_add_handle($multi_handle, $handle): int {}
function curl_multi_add_handle(CurlMultiHandle $multi_handle, CurlHandle $handle): int {}

/** @param resource $multi_handle */
function curl_multi_close($multi_handle): void {}
function curl_multi_close(CurlMultiHandle $multi_handle): void {}

/** @param resource $multi_handle */
function curl_multi_errno($multi_handle): int {}
function curl_multi_errno(CurlMultiHandle $multi_handle): int {}

/** @param resource $multi_handle */
function curl_multi_exec($multi_handle, &$still_running): int {}
/** @param int $still_running */
function curl_multi_exec(CurlMultiHandle $multi_handle, &$still_running): int {}

/** @param resource $multi_handle */
function curl_multi_getcontent($multi_handle): ?string {}
function curl_multi_getcontent(CurlHandle $multi_handle): ?string {}

/** @param resource $multi_handle */
function curl_multi_info_read($multi_handle, &$msgs_in_queue = null): array|false {}
/** @param int|null $msgs_in_queue */
function curl_multi_info_read(CurlMultiHandle $multi_handle, &$msgs_in_queue = null): array|false {}

/** @return resource */
function curl_multi_init() {}
function curl_multi_init(): CurlMultiHandle {}

/**
* @param resource $multi_handle
* @param resource $handle
*/
function curl_multi_remove_handle($multi_handle, $handle): int {}
function curl_multi_remove_handle(CurlMultiHandle $multi_handle, CurlHandle $handle): int {}

/** @param resource $multi_handle */
function curl_multi_select($multi_handle, float $timeout = 1.0): int {}
function curl_multi_select(CurlMultiHandle $multi_handle, float $timeout = 1.0): int {}

function curl_multi_strerror(int $error_number): ?string {}

#if LIBCURL_VERSION_NUM >= 0x071200 /* 7.18.0 */
/** @param resource $handle */
function curl_pause($handle, int $bitmask): int {}
function curl_pause(CurlHandle $handle, int $bitmask): int {}
#endif

/** @param resource $handle */
function curl_reset($handle): void {}
function curl_reset(CurlHandle $handle): void {}

/** @param resource $handle */
function curl_setopt_array($handle, array $options): bool {}
function curl_setopt_array(CurlHandle $handle, array $options): bool {}

/**
* @param resource $handle
* @param mixed $value
*/
function curl_setopt($handle, int $option, $value): bool {}
function curl_setopt(CurlHandle $handle, int $option, mixed $value): bool {}

/** @param resource $share_handle */
function curl_share_close($share_handle): void {}
function curl_share_close(CurlShareHandle $share_handle): void {}

/** @param resource $share_handle */
function curl_share_errno($share_handle): int {}
function curl_share_errno(CurlShareHandle $share_handle): int {}

/** @return resource */
function curl_share_init() {}
function curl_share_init(): CurlShareHandle {}

/** @param resource $share_handle */
function curl_share_setopt($share_handle, int $option, $value): bool {}
function curl_share_setopt(CurlShareHandle $share_handle, int $option, mixed $value): bool {}

function curl_share_strerror(int $error_number): ?string {}

Expand Down
76 changes: 46 additions & 30 deletions ext/curl/curl_arginfo.h
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
/* This is a generated file, edit the .stub.php file instead. */

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_curl_close, 0, 1, IS_VOID, 0)
ZEND_ARG_INFO(0, handle)
ZEND_ARG_OBJ_INFO(0, handle, CurlHandle, 0)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_INFO_EX(arginfo_curl_copy_handle, 0, 0, 1)
ZEND_ARG_INFO(0, handle)
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_curl_copy_handle, 0, 1, CurlHandle, MAY_BE_FALSE)
ZEND_ARG_OBJ_INFO(0, handle, CurlHandle, 0)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_curl_errno, 0, 1, IS_LONG, 0)
ZEND_ARG_INFO(0, handle)
ZEND_ARG_OBJ_INFO(0, handle, CurlHandle, 0)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_curl_error, 0, 1, IS_STRING, 0)
ZEND_ARG_INFO(0, handle)
ZEND_ARG_OBJ_INFO(0, handle, CurlHandle, 0)
ZEND_END_ARG_INFO()

#if LIBCURL_VERSION_NUM >= 0x070f04 /* 7.15.4 */
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_curl_escape, 0, 2, MAY_BE_STRING|MAY_BE_FALSE)
ZEND_ARG_INFO(0, handle)
ZEND_ARG_OBJ_INFO(0, handle, CurlHandle, 0)
ZEND_ARG_TYPE_INFO(0, string, IS_STRING, 0)
ZEND_END_ARG_INFO()
#endif
Expand All @@ -29,14 +29,14 @@ ZEND_END_ARG_INFO()

#if LIBCURL_VERSION_NUM >= 0x070f04 /* 7.15.4 */
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_curl_multi_setopt, 0, 3, _IS_BOOL, 0)
ZEND_ARG_INFO(0, multi_handle)
ZEND_ARG_OBJ_INFO(0, multi_handle, CurlMultiHandle, 0)
ZEND_ARG_TYPE_INFO(0, option, IS_LONG, 0)
ZEND_ARG_INFO(0, value)
ZEND_ARG_TYPE_INFO(0, value, IS_MIXED, 0)
ZEND_END_ARG_INFO()
#endif

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_curl_exec, 0, 1, MAY_BE_STRING|MAY_BE_BOOL)
ZEND_ARG_INFO(0, handle)
ZEND_ARG_OBJ_INFO(0, handle, CurlHandle, 0)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_curl_file_create, 0, 1, CURLFile, 0)
Expand All @@ -45,49 +45,49 @@ ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_curl_file_create, 0, 1, CURLFile,
ZEND_ARG_TYPE_INFO(0, postname, IS_STRING, 0)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_INFO_EX(arginfo_curl_getinfo, 0, 0, 1)
ZEND_ARG_INFO(0, handle)
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_curl_getinfo, 0, 1, IS_MIXED, 0)
ZEND_ARG_OBJ_INFO(0, handle, CurlHandle, 0)
ZEND_ARG_TYPE_INFO(0, option, IS_LONG, 0)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_INFO_EX(arginfo_curl_init, 0, 0, 0)
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_curl_init, 0, 0, CurlHandle, MAY_BE_FALSE)
ZEND_ARG_TYPE_INFO(0, url, IS_STRING, 0)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_curl_multi_add_handle, 0, 2, IS_LONG, 0)
ZEND_ARG_INFO(0, multi_handle)
ZEND_ARG_INFO(0, handle)
ZEND_ARG_OBJ_INFO(0, multi_handle, CurlMultiHandle, 0)
ZEND_ARG_OBJ_INFO(0, handle, CurlHandle, 0)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_curl_multi_close, 0, 1, IS_VOID, 0)
ZEND_ARG_INFO(0, multi_handle)
ZEND_ARG_OBJ_INFO(0, multi_handle, CurlMultiHandle, 0)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_curl_multi_errno, 0, 1, IS_LONG, 0)
ZEND_ARG_INFO(0, multi_handle)
ZEND_ARG_OBJ_INFO(0, multi_handle, CurlMultiHandle, 0)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_curl_multi_exec, 0, 2, IS_LONG, 0)
ZEND_ARG_INFO(0, multi_handle)
ZEND_ARG_OBJ_INFO(0, multi_handle, CurlMultiHandle, 0)
ZEND_ARG_INFO(1, still_running)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_curl_multi_getcontent, 0, 1, IS_STRING, 1)
ZEND_ARG_INFO(0, multi_handle)
ZEND_ARG_OBJ_INFO(0, multi_handle, CurlHandle, 0)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_curl_multi_info_read, 0, 1, MAY_BE_ARRAY|MAY_BE_FALSE)
ZEND_ARG_INFO(0, multi_handle)
ZEND_ARG_OBJ_INFO(0, multi_handle, CurlMultiHandle, 0)
ZEND_ARG_INFO_WITH_DEFAULT_VALUE(1, msgs_in_queue, "null")
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_INFO_EX(arginfo_curl_multi_init, 0, 0, 0)
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_curl_multi_init, 0, 0, CurlMultiHandle, 0)
ZEND_END_ARG_INFO()

#define arginfo_curl_multi_remove_handle arginfo_curl_multi_add_handle

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_curl_multi_select, 0, 1, IS_LONG, 0)
ZEND_ARG_INFO(0, multi_handle)
ZEND_ARG_OBJ_INFO(0, multi_handle, CurlMultiHandle, 0)
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, timeout, IS_DOUBLE, 0, "1.0")
ZEND_END_ARG_INFO()

Expand All @@ -97,38 +97,39 @@ ZEND_END_ARG_INFO()

#if LIBCURL_VERSION_NUM >= 0x071200 /* 7.18.0 */
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_curl_pause, 0, 2, IS_LONG, 0)
ZEND_ARG_INFO(0, handle)
ZEND_ARG_OBJ_INFO(0, handle, CurlHandle, 0)
ZEND_ARG_TYPE_INFO(0, bitmask, IS_LONG, 0)
ZEND_END_ARG_INFO()
#endif

#define arginfo_curl_reset arginfo_curl_close

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_curl_setopt_array, 0, 2, _IS_BOOL, 0)
ZEND_ARG_INFO(0, handle)
ZEND_ARG_OBJ_INFO(0, handle, CurlHandle, 0)
ZEND_ARG_TYPE_INFO(0, options, IS_ARRAY, 0)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_curl_setopt, 0, 3, _IS_BOOL, 0)
ZEND_ARG_INFO(0, handle)
ZEND_ARG_OBJ_INFO(0, handle, CurlHandle, 0)
ZEND_ARG_TYPE_INFO(0, option, IS_LONG, 0)
ZEND_ARG_INFO(0, value)
ZEND_ARG_TYPE_INFO(0, value, IS_MIXED, 0)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_curl_share_close, 0, 1, IS_VOID, 0)
ZEND_ARG_INFO(0, share_handle)
ZEND_ARG_OBJ_INFO(0, share_handle, CurlShareHandle, 0)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_curl_share_errno, 0, 1, IS_LONG, 0)
ZEND_ARG_INFO(0, share_handle)
ZEND_ARG_OBJ_INFO(0, share_handle, CurlShareHandle, 0)
ZEND_END_ARG_INFO()

#define arginfo_curl_share_init arginfo_curl_multi_init
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_curl_share_init, 0, 0, CurlShareHandle, 0)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_curl_share_setopt, 0, 3, _IS_BOOL, 0)
ZEND_ARG_INFO(0, share_handle)
ZEND_ARG_OBJ_INFO(0, share_handle, CurlShareHandle, 0)
ZEND_ARG_TYPE_INFO(0, option, IS_LONG, 0)
ZEND_ARG_INFO(0, value)
ZEND_ARG_TYPE_INFO(0, value, IS_MIXED, 0)
ZEND_END_ARG_INFO()

#define arginfo_curl_share_strerror arginfo_curl_multi_strerror
Expand Down Expand Up @@ -225,3 +226,18 @@ static const zend_function_entry ext_functions[] = {
ZEND_FE(curl_version, arginfo_curl_version)
ZEND_FE_END
};


static const zend_function_entry class_CurlHandle_methods[] = {
ZEND_FE_END
};


static const zend_function_entry class_CurlMultiHandle_methods[] = {
ZEND_FE_END
};


static const zend_function_entry class_CurlShareHandle_methods[] = {
ZEND_FE_END
};
Loading