preg_replace_error2.phpt 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. --TEST--
  2. Test 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. */
  9. error_reporting(E_ALL&~E_NOTICE);
  10. /*
  11. * Testing how preg_replace reacts to being passed the wrong type of replacement argument
  12. */
  13. echo "*** 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';
  17. foreach($replace as $value) {
  18. print "\nArg value is: $value\n";
  19. var_dump(preg_replace($regex, $value, $subject));
  20. }
  21. $value = new stdclass(); //Object
  22. var_dump(preg_replace($regex, $value, $subject));
  23. echo "Done";
  24. ?>
  25. --EXPECTF--
  26. *** Testing preg_replace() : error conditions ***
  27. Arg value is: this is a string
  28. string(64) "this is a stringthis is a stringthis is a stringthis is a string"
  29. Arg value is: Array
  30. Warning: preg_replace(): Parameter mismatch, pattern is a string while replacement is an array in %spreg_replace_error2.php on line %d
  31. bool(false)
  32. Catchable fatal error: Object of class stdClass could not be converted to string in %spreg_replace_error2.php on line %d