@@ -104,7 +104,7 @@ static int php_curl_option_str(php_curl *ch, zend_long option, const char *str,
104
104
CURLcode error = CURLE_OK ;
105
105
106
106
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 () );
108
108
return FAILURE ;
109
109
}
110
110
@@ -2204,7 +2204,7 @@ PHP_FUNCTION(curl_copy_handle)
2204
2204
}
2205
2205
/* }}} */
2206
2206
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 ) /* {{{ */
2208
2208
{
2209
2209
CURLcode error = CURLE_OK ;
2210
2210
zend_long lval ;
@@ -2381,7 +2381,7 @@ static int _php_curl_setopt(php_curl *ch, zend_long option, zval *zvalue) /* {{{
2381
2381
break ;
2382
2382
case CURLOPT_SAFE_UPLOAD :
2383
2383
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 () );
2385
2385
return FAILURE ;
2386
2386
}
2387
2387
break ;
@@ -2557,7 +2557,7 @@ static int _php_curl_setopt(php_curl *ch, zend_long option, zval *zvalue) /* {{{
2557
2557
ch -> handlers -> write -> method = PHP_CURL_FILE ;
2558
2558
ZVAL_COPY (& ch -> handlers -> write -> stream , zvalue );
2559
2559
} 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 () );
2561
2561
return FAILURE ;
2562
2562
}
2563
2563
break ;
@@ -2575,7 +2575,7 @@ static int _php_curl_setopt(php_curl *ch, zend_long option, zval *zvalue) /* {{{
2575
2575
ch -> handlers -> write_header -> method = PHP_CURL_FILE ;
2576
2576
ZVAL_COPY (& ch -> handlers -> write_header -> stream , zvalue );
2577
2577
} 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 () );
2579
2579
return FAILURE ;
2580
2580
}
2581
2581
break ;
@@ -2604,7 +2604,7 @@ static int _php_curl_setopt(php_curl *ch, zend_long option, zval *zvalue) /* {{{
2604
2604
zval_ptr_dtor (& ch -> handlers -> std_err );
2605
2605
ZVAL_COPY (& ch -> handlers -> std_err , zvalue );
2606
2606
} 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 () );
2608
2608
return FAILURE ;
2609
2609
}
2610
2610
/* break omitted intentionally */
@@ -2674,7 +2674,8 @@ static int _php_curl_setopt(php_curl *ch, zend_long option, zval *zvalue) /* {{{
2674
2674
break ;
2675
2675
#endif
2676
2676
}
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 );
2678
2679
return FAILURE ;
2679
2680
}
2680
2681
@@ -2850,6 +2851,14 @@ static int _php_curl_setopt(php_curl *ch, zend_long option, zval *zvalue) /* {{{
2850
2851
ch -> handlers -> fnmatch -> method = PHP_CURL_USER ;
2851
2852
break ;
2852
2853
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 ;
2853
2862
}
2854
2863
2855
2864
SAVE_CURL_ERROR (ch , error );
@@ -2876,12 +2885,7 @@ PHP_FUNCTION(curl_setopt)
2876
2885
2877
2886
ch = Z_CURL_P (zid );
2878
2887
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 ) {
2885
2889
RETURN_TRUE ;
2886
2890
} else {
2887
2891
RETURN_FALSE ;
@@ -2906,12 +2910,12 @@ PHP_FUNCTION(curl_setopt_array)
2906
2910
2907
2911
ZEND_HASH_FOREACH_KEY_VAL (Z_ARRVAL_P (arr ), option , string_key , entry ) {
2908
2912
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 ();
2912
2915
}
2916
+
2913
2917
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 ) {
2915
2919
RETURN_FALSE ;
2916
2920
}
2917
2921
} ZEND_HASH_FOREACH_END ();
@@ -3292,8 +3296,8 @@ PHP_FUNCTION(curl_close)
3292
3296
ch = Z_CURL_P (zid );
3293
3297
3294
3298
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 () ;
3297
3301
}
3298
3302
}
3299
3303
/* }}} */
@@ -3449,8 +3453,8 @@ PHP_FUNCTION(curl_reset)
3449
3453
ch = Z_CURL_P (zid );
3450
3454
3451
3455
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 () ;
3454
3458
}
3455
3459
3456
3460
curl_easy_reset (ch -> cp );
0 commit comments