2 Test preg_replace() function : error conditions - wrong arg types
6 * proto string preg_replace(mixed regex, mixed replace, mixed subject [, int limit [, count]])
7 * Function is implemented in ext/pcre/php_pcre.c
10 * Testing how preg_replace reacts to being passed the wrong type of replacement argument
12 echo "*** Testing preg_replace() : error conditions ***\n";
13 $regex = '/[a-zA-Z]/';
14 $replace = array('this is a string', array('this is', 'a subarray'),);
16 foreach($replace as $value) {
17 @print "\nArg value is: $value\n";
19 var_dump(preg_replace($regex, $value, $subject));
20 } catch (TypeError $e) {
21 echo $e->getMessage(), "\n";
24 $value = new stdclass(); //Object
26 var_dump(preg_replace($regex, $value, $subject));
28 echo $e->getMessage(), "\n";
33 *** Testing preg_replace() : error conditions ***
35 Arg value is: this is a string
36 string(64) "this is a stringthis is a stringthis is a stringthis is a string"
39 preg_replace(): Argument #1 ($regex) must be of type array when argument #2 ($replace) is an array, string given
40 Object of class stdClass could not be converted to string