@@ -2265,87 +2265,87 @@ PHP_FUNCTION(substr_replace)
2265
2265
}
2266
2266
2267
2267
if (str ) {
2268
- if (( len_is_null && from_ht ) || (! len_is_null && ( from_ht == NULL ) != ( len_ht == NULL )) ) {
2269
- php_error_docref ( NULL , E_WARNING , "'start' and 'length' should be of same type - numerical or array " );
2270
- RETURN_STR_COPY ( str );
2268
+ if (from_ht ) {
2269
+ zend_argument_type_error ( 3 , "cannot be an array when working on a single string " );
2270
+ RETURN_THROWS ( );
2271
2271
}
2272
- if (!len_is_null && from_ht ) {
2273
- if (zend_hash_num_elements (from_ht ) != zend_hash_num_elements (len_ht )) {
2274
- php_error_docref (NULL , E_WARNING , "'start' and 'length' should have the same number of elements" );
2275
- RETURN_STR_COPY (str );
2276
- }
2272
+ if (len_ht ) {
2273
+ zend_argument_type_error (4 , "cannot be an array when working on a single string" );
2274
+ RETURN_THROWS ();
2277
2275
}
2278
- }
2279
2276
2280
- if (str ) {
2281
- if (!from_ht ) {
2282
- f = from_long ;
2277
+ f = from_long ;
2283
2278
2284
- /* if "from" position is negative, count start position from the end
2285
- * of the string
2286
- */
2279
+ /* if "from" position is negative, count start position from the end
2280
+ * of the string
2281
+ */
2282
+ if (f < 0 ) {
2283
+ f = (zend_long )ZSTR_LEN (str ) + f ;
2287
2284
if (f < 0 ) {
2288
- f = (zend_long )ZSTR_LEN (str ) + f ;
2289
- if (f < 0 ) {
2290
- f = 0 ;
2291
- }
2292
- } else if ((size_t )f > ZSTR_LEN (str )) {
2293
- f = ZSTR_LEN (str );
2285
+ f = 0 ;
2294
2286
}
2295
- /* if "length" position is negative, set it to the length
2296
- * needed to stop that many chars from the end of the string
2297
- */
2287
+ } else if ((size_t )f > ZSTR_LEN (str )) {
2288
+ f = ZSTR_LEN (str );
2289
+ }
2290
+ /* if "length" position is negative, set it to the length
2291
+ * needed to stop that many chars from the end of the string
2292
+ */
2293
+ if (l < 0 ) {
2294
+ l = ((zend_long )ZSTR_LEN (str ) - f ) + l ;
2298
2295
if (l < 0 ) {
2299
- l = ((zend_long )ZSTR_LEN (str ) - f ) + l ;
2300
- if (l < 0 ) {
2301
- l = 0 ;
2302
- }
2296
+ l = 0 ;
2303
2297
}
2298
+ }
2304
2299
2305
- if ((size_t )l > ZSTR_LEN (str ) || (l < 0 && (size_t )(- l ) > ZSTR_LEN (str ))) {
2306
- l = ZSTR_LEN (str );
2307
- }
2300
+ if ((size_t )l > ZSTR_LEN (str ) || (l < 0 && (size_t )(- l ) > ZSTR_LEN (str ))) {
2301
+ l = ZSTR_LEN (str );
2302
+ }
2308
2303
2309
- if ((f + l ) > (zend_long )ZSTR_LEN (str )) {
2310
- l = ZSTR_LEN (str ) - f ;
2311
- }
2304
+ if ((f + l ) > (zend_long )ZSTR_LEN (str )) {
2305
+ l = ZSTR_LEN (str ) - f ;
2306
+ }
2312
2307
2313
- zend_string * tmp_repl_str = NULL ;
2314
- if (repl_ht ) {
2315
- repl_idx = 0 ;
2316
- while (repl_idx < repl_ht -> nNumUsed ) {
2317
- tmp_repl = & repl_ht -> arData [repl_idx ].val ;
2318
- if (Z_TYPE_P (tmp_repl ) != IS_UNDEF ) {
2319
- break ;
2320
- }
2321
- repl_idx ++ ;
2322
- }
2323
- if (repl_idx < repl_ht -> nNumUsed ) {
2324
- repl_str = zval_get_tmp_string (tmp_repl , & tmp_repl_str );
2325
- } else {
2326
- repl_str = STR_EMPTY_ALLOC ();
2308
+ zend_string * tmp_repl_str = NULL ;
2309
+ if (repl_ht ) {
2310
+ repl_idx = 0 ;
2311
+ while (repl_idx < repl_ht -> nNumUsed ) {
2312
+ tmp_repl = & repl_ht -> arData [repl_idx ].val ;
2313
+ if (Z_TYPE_P (tmp_repl ) != IS_UNDEF ) {
2314
+ break ;
2327
2315
}
2316
+ repl_idx ++ ;
2328
2317
}
2318
+ if (repl_idx < repl_ht -> nNumUsed ) {
2319
+ repl_str = zval_get_tmp_string (tmp_repl , & tmp_repl_str );
2320
+ } else {
2321
+ repl_str = STR_EMPTY_ALLOC ();
2322
+ }
2323
+ }
2329
2324
2330
- result = zend_string_safe_alloc (1 , ZSTR_LEN (str ) - l + ZSTR_LEN (repl_str ), 0 , 0 );
2325
+ result = zend_string_safe_alloc (1 , ZSTR_LEN (str ) - l + ZSTR_LEN (repl_str ), 0 , 0 );
2331
2326
2332
- memcpy (ZSTR_VAL (result ), ZSTR_VAL (str ), f );
2333
- if (ZSTR_LEN (repl_str )) {
2334
- memcpy ((ZSTR_VAL (result ) + f ), ZSTR_VAL (repl_str ), ZSTR_LEN (repl_str ));
2335
- }
2336
- memcpy ((ZSTR_VAL (result ) + f + ZSTR_LEN (repl_str )), ZSTR_VAL (str ) + f + l , ZSTR_LEN (str ) - f - l );
2337
- ZSTR_VAL (result )[ZSTR_LEN (result )] = '\0' ;
2338
- zend_tmp_string_release (tmp_repl_str );
2339
- RETURN_NEW_STR (result );
2340
- } else {
2341
- php_error_docref (NULL , E_WARNING , "Functionality of 'start' and 'length' as arrays is not implemented" );
2342
- RETURN_STR_COPY (str );
2327
+ memcpy (ZSTR_VAL (result ), ZSTR_VAL (str ), f );
2328
+ if (ZSTR_LEN (repl_str )) {
2329
+ memcpy ((ZSTR_VAL (result ) + f ), ZSTR_VAL (repl_str ), ZSTR_LEN (repl_str ));
2343
2330
}
2331
+ memcpy ((ZSTR_VAL (result ) + f + ZSTR_LEN (repl_str )), ZSTR_VAL (str ) + f + l , ZSTR_LEN (str ) - f - l );
2332
+ ZSTR_VAL (result )[ZSTR_LEN (result )] = '\0' ;
2333
+ zend_tmp_string_release (tmp_repl_str );
2334
+ RETURN_NEW_STR (result );
2344
2335
} else { /* str is array of strings */
2345
2336
zend_string * str_index = NULL ;
2346
2337
size_t result_len ;
2347
2338
zend_ulong num_index ;
2348
2339
2340
+ /* TODO
2341
+ if (!len_is_null && from_ht) {
2342
+ if (zend_hash_num_elements(from_ht) != zend_hash_num_elements(len_ht)) {
2343
+ php_error_docref(NULL, E_WARNING, "'start' and 'length' should have the same number of elements");
2344
+ RETURN_STR_COPY(str);
2345
+ }
2346
+ }
2347
+ */
2348
+
2349
2349
array_init (return_value );
2350
2350
2351
2351
from_idx = len_idx = repl_idx = 0 ;
0 commit comments