1--TEST-- 2Test preg_replace() function : error - bad regular expressions 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 regex argument 12*/ 13echo "*** Testing preg_replace() : error conditions***\n"; 14$regex_array = array('abcdef', //Regex without delimeter 15'/[a-zA-Z]', //Regex without closing delimeter 16'[a-zA-Z]/', //Regex without opening delimeter 17'/[a-zA-Z]/F', array('[a-z]', //Array of Regexes 18'[A-Z]', '[0-9]'), '/[a-zA-Z]/', //Regex string 19); 20$replace = 1; 21$subject = 'a'; 22foreach($regex_array as $regex_value) { 23 print "\nArg value is $regex_value\n"; 24 var_dump(preg_replace($regex_value, $replace, $subject)); 25} 26$regex_value = new stdclass(); //Object 27var_dump(preg_replace($regex_value, $replace, $subject)); 28?> 29--EXPECTF-- 30*** Testing preg_replace() : error conditions*** 31 32Arg value is abcdef 33 34Warning: preg_replace(): Delimiter must not be alphanumeric or backslash in %spreg_replace_error1.php on line %d 35NULL 36 37Arg value is /[a-zA-Z] 38 39Warning: preg_replace(): No ending delimiter '/' found in %spreg_replace_error1.php on line %d 40NULL 41 42Arg value is [a-zA-Z]/ 43 44Warning: preg_replace(): Unknown modifier '/' in %spreg_replace_error1.php on line %d 45NULL 46 47Arg value is /[a-zA-Z]/F 48 49Warning: preg_replace(): Unknown modifier 'F' in %spreg_replace_error1.php on line %d 50NULL 51 52Arg value is Array 53string(1) "a" 54 55Arg value is /[a-zA-Z]/ 56string(1) "1" 57 58Catchable fatal error: Object of class stdClass could not be converted to string in %spreg_replace_error1.php on line %d 59 60