CURLcode error = CURLE_OK;
if (strlen(str) != len) {
- php_error_docref(NULL, E_WARNING, "Curl option contains invalid characters (\\0)");
+ zend_type_error("%s(): cURL option cannot contain any null-bytes", get_active_function_name());
return FAILURE;
}
}
/* }}} */
-static int _php_curl_setopt(php_curl *ch, zend_long option, zval *zvalue) /* {{{ */
+static int _php_curl_setopt(php_curl *ch, zend_long option, zval *zvalue, bool is_array_config) /* {{{ */
{
CURLcode error = CURLE_OK;
zend_long lval;
break;
case CURLOPT_SAFE_UPLOAD:
if (!zend_is_true(zvalue)) {
- php_error_docref(NULL, E_WARNING, "Disabling safe uploads is no longer supported");
+ zend_value_error("%s(): Disabling safe uploads is no longer supported", get_active_function_name());
return FAILURE;
}
break;
ch->handlers->write->method = PHP_CURL_FILE;
ZVAL_COPY(&ch->handlers->write->stream, zvalue);
} else {
- php_error_docref(NULL, E_WARNING, "The provided file handle is not writable");
+ zend_value_error("%s(): The provided file handle must be writable", get_active_function_name());
return FAILURE;
}
break;
ch->handlers->write_header->method = PHP_CURL_FILE;
ZVAL_COPY(&ch->handlers->write_header->stream, zvalue);
} else {
- php_error_docref(NULL, E_WARNING, "The provided file handle is not writable");
+ zend_value_error("%s(): The provided file handle must be writable", get_active_function_name());
return FAILURE;
}
break;
zval_ptr_dtor(&ch->handlers->std_err);
ZVAL_COPY(&ch->handlers->std_err, zvalue);
} else {
- php_error_docref(NULL, E_WARNING, "The provided file handle is not writable");
+ zend_value_error("%s(): The provided file handle must be writable", get_active_function_name());
return FAILURE;
}
/* break omitted intentionally */
break;
#endif
}
- php_error_docref(NULL, E_WARNING, "You must pass an array with the %s argument", name);
+
+ zend_type_error("%s(): The %s option must have an array value", get_active_function_name(), name);
return FAILURE;
}
ch->handlers->fnmatch->method = PHP_CURL_USER;
break;
+ default:
+ if (is_array_config) {
+ zend_argument_value_error(2, "must contain only valid cURL options");
+ } else {
+ zend_argument_value_error(2, "is not a valid cURL option");
+ }
+ error = CURLE_UNKNOWN_OPTION;
+ break;
}
SAVE_CURL_ERROR(ch, error);
ch = Z_CURL_P(zid);
- if (options <= 0 && options != CURLOPT_SAFE_UPLOAD) {
- php_error_docref(NULL, E_WARNING, "Invalid curl configuration option");
- RETURN_FALSE;
- }
-
- if (_php_curl_setopt(ch, options, zvalue) == SUCCESS) {
+ if (_php_curl_setopt(ch, options, zvalue, 0) == SUCCESS) {
RETURN_TRUE;
} else {
RETURN_FALSE;
ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(arr), option, string_key, entry) {
if (string_key) {
- php_error_docref(NULL, E_WARNING,
- "Array keys must be CURLOPT constants or equivalent integer values");
- RETURN_FALSE;
+ zend_argument_value_error(2, "contains an invalid cURL option");
+ RETURN_THROWS();
}
+
ZVAL_DEREF(entry);
- if (_php_curl_setopt(ch, (zend_long) option, entry) == FAILURE) {
+ if (_php_curl_setopt(ch, (zend_long) option, entry, 1) == FAILURE) {
RETURN_FALSE;
}
} ZEND_HASH_FOREACH_END();
ch = Z_CURL_P(zid);
if (ch->in_callback) {
- php_error_docref(NULL, E_WARNING, "Attempt to close cURL handle from a callback");
- return;
+ zend_throw_error(NULL, "%s(): Attempt to close cURL handle from a callback", get_active_function_name());
+ RETURN_THROWS();
}
}
/* }}} */
ch = Z_CURL_P(zid);
if (ch->in_callback) {
- php_error_docref(NULL, E_WARNING, "Attempt to reset cURL handle from a callback");
- return;
+ zend_throw_error(NULL, "%s(): Attempt to reset cURL handle from a callback", get_active_function_name());
+ RETURN_THROWS();
}
curl_easy_reset(ch->cp);
break;
#endif
default:
- php_error_docref(NULL, E_WARNING, "Invalid curl multi configuration option");
+ zend_argument_value_error(2, "is not a valid cURL multi option");
error = CURLM_UNKNOWN_OPTION;
break;
}
break;
default:
- php_error_docref(NULL, E_WARNING, "Invalid curl share configuration option");
+ zend_argument_value_error(2, "is not a valid cURL share option");
error = CURLSHE_BAD_OPTION;
break;
}
$tempfile = tempnam(sys_get_temp_dir(), 'CURL_FILE_HANDLE');
+$fp = fopen($tempfile, "r"); // Opening 'fubar' with the incorrect readonly flag
$ch = curl_init($url);
-$fp = fopen($tempfile, "r"); // Opening 'fubar' with the incorrect readonly flag
-curl_setopt($ch, CURLOPT_FILE, $fp);
+try {
+ curl_setopt($ch, CURLOPT_FILE, $fp);
+} catch (ValueError $exception) {
+ echo $exception->getMessage() . "\n";
+}
+
curl_exec($ch);
curl_close($ch);
is_file($tempfile) and @unlink($tempfile);
isset($tempname) and is_file($tempname) and @unlink($tempname);
?>
---EXPECTF--
-Warning: curl_setopt(): The provided file handle is not writable in %s on line %d
+--EXPECT--
+curl_setopt(): The provided file handle must be writable
Hello World!
Hello World!
<?php
$url = "file:///etc/passwd\0http://google.com";
$ch = curl_init();
-var_dump(curl_setopt($ch, CURLOPT_URL, $url));
+
+try {
+ curl_setopt($ch, CURLOPT_URL, $url);
+} catch (TypeError $exception) {
+ echo $exception->getMessage() . "\n";
+}
+
?>
Done
---EXPECTF--
-Warning: curl_setopt(): Curl option contains invalid characters (\0) in %s%ebug68089.php on line 4
-bool(false)
+--EXPECT--
+curl_setopt(): cURL option cannot contain any null-bytes
Done
curl_setopt($ch, CURLOPT_POSTFIELDS, array("file" => $file));
var_dump(curl_exec($ch));
-curl_setopt($ch, CURLOPT_SAFE_UPLOAD, 0);
+try {
+ curl_setopt($ch, CURLOPT_SAFE_UPLOAD, 0);
+} catch (ValueError $exception) {
+ echo $exception->getMessage() . "\n";
+}
+
$params = array('file' => '@' . __DIR__ . '/curl_testdata1.txt');
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
var_dump(curl_exec($ch));
string(%d) "curl_testdata1.txt|text/plain|6"
string(%d) "foo.txt"
string(%d) "foo.txt|application/octet-stream|6"
-
-Warning: curl_setopt(): Disabling safe uploads is no longer supported in %s on line %d
+curl_setopt(): Disabling safe uploads is no longer supported
string(0) ""
string(0) ""
string(%d) "array(1) {
echo $errno . PHP_EOL;
echo curl_multi_strerror($errno) . PHP_EOL;
-@curl_multi_setopt($mh, -1, -1);
+try {
+ curl_multi_setopt($mh, -1, -1);
+} catch (ValueError $exception) {
+ echo $exception->getMessage() . "\n";
+}
+
$errno = curl_multi_errno($mh);
echo $errno . PHP_EOL;
echo curl_multi_strerror($errno) . PHP_EOL;
--EXPECT--
0
No error
+curl_multi_setopt(): Argument #2 ($option) is not a valid cURL multi option
6
Unknown option
$mh = curl_multi_init();
var_dump(curl_multi_setopt($mh, CURLMOPT_PIPELINING, 0));
-var_dump(curl_multi_setopt($mh, -1, 0));
+
+try {
+ curl_multi_setopt($mh, -1, 0);
+} catch (ValueError $exception) {
+ echo $exception->getMessage() . "\n";
+}
?>
---EXPECTF--
+--EXPECT--
bool(true)
-
-Warning: curl_multi_setopt(): Invalid curl multi configuration option in %s on line %d
-bool(false)
+curl_multi_setopt(): Argument #2 ($option) is not a valid cURL multi option
$url = "{$host}/";
$ch = curl_init();
-curl_setopt($ch, CURLOPT_HTTPHEADER, 1);
+try {
+ curl_setopt($ch, CURLOPT_HTTPHEADER, 1);
+} catch (TypeError $exception) {
+ echo $exception->getMessage() . "\n";
+}
$curl_content = curl_exec($ch);
curl_close($ch);
var_dump( $curl_content );
?>
---EXPECTF--
+--EXPECT--
*** curl_setopt() call with CURLOPT_HTTPHEADER
-
-Warning: curl_setopt(): You must pass an array with the CURLOPT_HTTPHEADER argument in %s on line %d
+curl_setopt(): The CURLOPT_HTTPHEADER option must have an array value
bool(false)
bool(true)
echo $e->getMessage(), "\n";
}
-curl_setopt($ch, -10, 0);
+try {
+ curl_setopt($ch, -10, 0);
+} catch (ValueError $e) {
+ echo $e->getMessage(), "\n";
+}
+
+try {
+ curl_setopt($ch, 1000, 0);
+} catch (ValueError $e) {
+ echo $e->getMessage(), "\n";
+}
+
?>
---EXPECTF--
+--EXPECT--
*** curl_setopt() call with incorrect parameters
curl_setopt(): Argument #2 ($option) must be of type int, string given
-
-Warning: curl_setopt(): Invalid curl configuration option in %scurl_setopt_error.php on line %d
+curl_setopt(): Argument #2 ($option) is not a valid cURL option
+curl_setopt(): Argument #2 ($option) is not a valid cURL option
echo $errno . PHP_EOL;
echo curl_share_strerror($errno) . PHP_EOL;
-@curl_share_setopt($sh, -1, -1);
+try {
+ curl_share_setopt($sh, -1, -1);
+} catch (ValueError $e) {
+ echo $e->getMessage(), "\n";
+}
+
$errno = curl_share_errno($sh);
echo $errno . PHP_EOL;
echo curl_share_strerror($errno) . PHP_EOL;
--EXPECT--
0
No error
+curl_share_setopt(): Argument #2 ($option) is not a valid cURL share option
1
Unknown share option
$sh = curl_share_init();
var_dump(curl_share_setopt($sh, CURLSHOPT_SHARE, CURL_LOCK_DATA_COOKIE));
var_dump(curl_share_setopt($sh, CURLSHOPT_UNSHARE, CURL_LOCK_DATA_DNS));
-var_dump(curl_share_setopt($sh, -1, 0));
+
+try {
+ curl_share_setopt($sh, -1, 0);
+} catch (ValueError $e) {
+ echo $e->getMessage(), "\n";
+}
?>
---EXPECTF--
+--EXPECT--
bool(true)
bool(true)
-
-Warning: curl_share_setopt(): Invalid curl share configuration option in %s on line %d
-bool(false)
+curl_share_setopt(): Argument #2 ($option) is not a valid cURL share option