@@ -104,7 +104,7 @@ static int php_curl_option_str(php_curl *ch, zend_long option, const char *str,
104104 CURLcode error = CURLE_OK ;
105105
106106 if (strlen (str ) != len ) {
107- php_error_docref ( NULL , E_WARNING , "Curl option contains invalid characters (\\0)" );
107+ zend_type_error ( "%s(): cURL option cannot contain any null-bytes" , get_active_function_name () );
108108 return FAILURE ;
109109 }
110110
@@ -2204,7 +2204,7 @@ PHP_FUNCTION(curl_copy_handle)
22042204}
22052205/* }}} */
22062206
2207- static int _php_curl_setopt (php_curl * ch , zend_long option , zval * zvalue ) /* {{{ */
2207+ static int _php_curl_setopt (php_curl * ch , zend_long option , zval * zvalue , bool is_array_config ) /* {{{ */
22082208{
22092209 CURLcode error = CURLE_OK ;
22102210 zend_long lval ;
@@ -2381,7 +2381,7 @@ static int _php_curl_setopt(php_curl *ch, zend_long option, zval *zvalue) /* {{{
23812381 break ;
23822382 case CURLOPT_SAFE_UPLOAD :
23832383 if (!zend_is_true (zvalue )) {
2384- php_error_docref ( NULL , E_WARNING , " Disabling safe uploads is no longer supported" );
2384+ zend_value_error ( "%s(): Disabling safe uploads is no longer supported", get_active_function_name () );
23852385 return FAILURE ;
23862386 }
23872387 break ;
@@ -2557,7 +2557,7 @@ static int _php_curl_setopt(php_curl *ch, zend_long option, zval *zvalue) /* {{{
25572557 ch -> handlers -> write -> method = PHP_CURL_FILE ;
25582558 ZVAL_COPY (& ch -> handlers -> write -> stream , zvalue );
25592559 } else {
2560- php_error_docref ( NULL , E_WARNING , " The provided file handle is not writable" );
2560+ zend_value_error ( "%s(): The provided file handle must be writable", get_active_function_name () );
25612561 return FAILURE ;
25622562 }
25632563 break ;
@@ -2575,7 +2575,7 @@ static int _php_curl_setopt(php_curl *ch, zend_long option, zval *zvalue) /* {{{
25752575 ch -> handlers -> write_header -> method = PHP_CURL_FILE ;
25762576 ZVAL_COPY (& ch -> handlers -> write_header -> stream , zvalue );
25772577 } else {
2578- php_error_docref ( NULL , E_WARNING , " The provided file handle is not writable" );
2578+ zend_value_error ( "%s(): The provided file handle must be writable", get_active_function_name () );
25792579 return FAILURE ;
25802580 }
25812581 break ;
@@ -2604,7 +2604,7 @@ static int _php_curl_setopt(php_curl *ch, zend_long option, zval *zvalue) /* {{{
26042604 zval_ptr_dtor (& ch -> handlers -> std_err );
26052605 ZVAL_COPY (& ch -> handlers -> std_err , zvalue );
26062606 } else {
2607- php_error_docref ( NULL , E_WARNING , " The provided file handle is not writable" );
2607+ zend_value_error ( "%s(): The provided file handle must be writable", get_active_function_name () );
26082608 return FAILURE ;
26092609 }
26102610 /* break omitted intentionally */
@@ -2674,7 +2674,8 @@ static int _php_curl_setopt(php_curl *ch, zend_long option, zval *zvalue) /* {{{
26742674 break ;
26752675#endif
26762676 }
2677- php_error_docref (NULL , E_WARNING , "You must pass an array with the %s argument" , name );
2677+
2678+ zend_type_error ("%s(): The %s option must have an array value" , get_active_function_name (), name );
26782679 return FAILURE ;
26792680 }
26802681
@@ -2850,6 +2851,14 @@ static int _php_curl_setopt(php_curl *ch, zend_long option, zval *zvalue) /* {{{
28502851 ch -> handlers -> fnmatch -> method = PHP_CURL_USER ;
28512852 break ;
28522853
2854+ default :
2855+ if (is_array_config ) {
2856+ zend_argument_value_error (2 , "must contain only valid cURL options" );
2857+ } else {
2858+ zend_argument_value_error (2 , "is not a valid cURL option" );
2859+ }
2860+ error = CURLE_UNKNOWN_OPTION ;
2861+ break ;
28532862 }
28542863
28552864 SAVE_CURL_ERROR (ch , error );
@@ -2876,12 +2885,7 @@ PHP_FUNCTION(curl_setopt)
28762885
28772886 ch = Z_CURL_P (zid );
28782887
2879- if (options <= 0 && options != CURLOPT_SAFE_UPLOAD ) {
2880- php_error_docref (NULL , E_WARNING , "Invalid curl configuration option" );
2881- RETURN_FALSE ;
2882- }
2883-
2884- if (_php_curl_setopt (ch , options , zvalue ) == SUCCESS ) {
2888+ if (_php_curl_setopt (ch , options , zvalue , 0 ) == SUCCESS ) {
28852889 RETURN_TRUE ;
28862890 } else {
28872891 RETURN_FALSE ;
@@ -2906,12 +2910,12 @@ PHP_FUNCTION(curl_setopt_array)
29062910
29072911 ZEND_HASH_FOREACH_KEY_VAL (Z_ARRVAL_P (arr ), option , string_key , entry ) {
29082912 if (string_key ) {
2909- php_error_docref (NULL , E_WARNING ,
2910- "Array keys must be CURLOPT constants or equivalent integer values" );
2911- RETURN_FALSE ;
2913+ zend_argument_value_error (2 , "contains an invalid cURL option" );
2914+ RETURN_THROWS ();
29122915 }
2916+
29132917 ZVAL_DEREF (entry );
2914- if (_php_curl_setopt (ch , (zend_long ) option , entry ) == FAILURE ) {
2918+ if (_php_curl_setopt (ch , (zend_long ) option , entry , 1 ) == FAILURE ) {
29152919 RETURN_FALSE ;
29162920 }
29172921 } ZEND_HASH_FOREACH_END ();
@@ -3292,8 +3296,8 @@ PHP_FUNCTION(curl_close)
32923296 ch = Z_CURL_P (zid );
32933297
32943298 if (ch -> in_callback ) {
3295- php_error_docref (NULL , E_WARNING , " Attempt to close cURL handle from a callback" );
3296- return ;
3299+ zend_throw_error (NULL , "%s(): Attempt to close cURL handle from a callback", get_active_function_name () );
3300+ RETURN_THROWS () ;
32973301 }
32983302}
32993303/* }}} */
@@ -3449,8 +3453,8 @@ PHP_FUNCTION(curl_reset)
34493453 ch = Z_CURL_P (zid );
34503454
34513455 if (ch -> in_callback ) {
3452- php_error_docref (NULL , E_WARNING , " Attempt to reset cURL handle from a callback" );
3453- return ;
3456+ zend_throw_error (NULL , "%s(): Attempt to reset cURL handle from a callback", get_active_function_name () );
3457+ RETURN_THROWS () ;
34543458 }
34553459
34563460 curl_easy_reset (ch -> cp );
0 commit comments