1--TEST--
2Test substr_replace() function : error conditions
3--FILE--
4<?php
5/* Prototype  : mixed substr_replace  ( mixed $string  , string $replacement  , int $start  [, int $length  ] )
6 * Description: Replace text within a portion of a string
7 * Source code: ext/standard/string.c
8*/
9
10/*
11 * Testing substr_replace() for error conditions
12*/
13
14echo "*** Testing substr_replace() : error conditions ***\n";
15
16$s1 = "Good morning";
17
18echo "\n-- Testing substr_replace() function with less than expected no. of arguments --\n";
19var_dump(substr_replace());
20var_dump(substr_replace($s1, "evening"));
21
22echo "\n-- Testing substr_replace() function with more than expected no. of arguments --\n";
23var_dump(substr_replace($s1, "evening", 5, 7, true));
24
25echo "\n-- Testing substr_replace() function with start and length different types --\n";
26var_dump(substr_replace($s1, "evening", array(5)));
27var_dump(substr_replace($s1, "evening", 5, array(8)));
28
29echo "\n-- Testing substr_replace() function with start and length with a different number of elments --\n";
30var_dump(substr_replace($s1, "evening", array(5, 1), array(8)));
31
32echo "\n-- Testing substr_replace() function with start and length as arrays but string not--\n";
33var_dump(substr_replace($s1, "evening", array(5), array(8)));
34
35?>
36===DONE===
37--EXPECTF--
38*** Testing substr_replace() : error conditions ***
39
40-- Testing substr_replace() function with less than expected no. of arguments --
41
42Warning: substr_replace() expects at least 3 parameters, 0 given in %s on line %d
43NULL
44
45Warning: substr_replace() expects at least 3 parameters, 2 given in %s on line %d
46NULL
47
48-- Testing substr_replace() function with more than expected no. of arguments --
49
50Warning: substr_replace() expects at most 4 parameters, 5 given in %s on line %d
51NULL
52
53-- Testing substr_replace() function with start and length different types --
54
55Warning: substr_replace(): 'from' and 'len' should be of same type - numerical or array  in %s on line %d
56string(12) "Good morning"
57
58Warning: substr_replace(): 'from' and 'len' should be of same type - numerical or array  in %s on line %d
59string(12) "Good morning"
60
61-- Testing substr_replace() function with start and length with a different number of elments --
62
63Warning: substr_replace(): 'from' and 'len' should have the same number of elements in %s on line %d
64string(12) "Good morning"
65
66-- Testing substr_replace() function with start and length as arrays but string not--
67
68Warning: substr_replace(): Functionality of 'from' and 'len' as arrays is not implemented in %s on line %d
69string(12) "Good morning"
70===DONE===