1--TEST-- 2Test preg_replace() function : error conditions - wrong arg types 3--FILE-- 4<?php 5/* 6* proto string preg_replace(mixed regex, mixed replace, mixed subject [, int limit [, count]]) 7* Function is implemented in ext/pcre/php_pcre.c 8*/ 9error_reporting(E_ALL&~E_NOTICE); 10/* 11* Testing how preg_replace reacts to being passed the wrong type of replacement argument 12*/ 13echo "*** Testing preg_replace() : error conditions ***\n"; 14$regex = '/[a-zA-Z]/'; 15$replace = array('this is a string', array('this is', 'a subarray'),); 16$subject = 'test'; 17foreach($replace as $value) { 18 print "\nArg value is: $value\n"; 19 var_dump(preg_replace($regex, $value, $subject)); 20} 21$value = new stdclass(); //Object 22try { 23 var_dump(preg_replace($regex, $value, $subject)); 24} catch (Error $e) { 25 echo $e->getMessage(), "\n"; 26} 27echo "Done"; 28?> 29--EXPECTF-- 30*** Testing preg_replace() : error conditions *** 31 32Arg value is: this is a string 33string(64) "this is a stringthis is a stringthis is a stringthis is a string" 34 35Arg value is: Array 36 37Warning: preg_replace(): Parameter mismatch, pattern is a string while replacement is an array in %spreg_replace_error2.php on line %d 38bool(false) 39Object of class stdClass could not be converted to string 40Done 41