Annotation of embedaddon/php/ext/pcre/tests/preg_replace_callback_error1.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: Test preg_replace_callback() function : error
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_callback reacts to being passed the wrong type of regex argument
12: */
13: echo "*** Testing preg_replace_callback() : error conditions ***\n";
14: $regex_array = array('abcdef', //Regex without delimiters
15: '/[a-zA-Z]', //Regex without closing delimiter
16: '[a-zA-Z]/', //Regex without opening delimiter
17: '/[a-zA-Z]/F', array('[a-z]', //Array of Regexes
18: '[A-Z]', '[0-9]'), '/[a-zA-Z]/'); //Regex string
19: $replacement = array('zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine');
20: function integer_word($matches) {
21: global $replacement;
22: return $replacement[$matches[0]];
23: }
24: $subject = 'number 1.';
25: foreach($regex_array as $regex_value) {
26: print "\nArg value is $regex_value\n";
27: var_dump(preg_replace_callback($regex_value, 'integer_word', $subject));
28: }
29: ?>
30: ===Done===
31: --EXPECTF--
32: *** Testing preg_replace_callback() : error conditions ***
33:
34: Arg value is abcdef
35:
36: Warning: preg_replace_callback(): Delimiter must not be alphanumeric or backslash in %s on line %d
37: NULL
38:
39: Arg value is /[a-zA-Z]
40:
41: Warning: preg_replace_callback(): No ending delimiter '/' found in %s on line %d
42: NULL
43:
44: Arg value is [a-zA-Z]/
45:
46: Warning: preg_replace_callback(): Unknown modifier '/' in %s on line %d
47: NULL
48:
49: Arg value is /[a-zA-Z]/F
50:
51: Warning: preg_replace_callback(): Unknown modifier 'F' in %s on line %d
52: NULL
53:
54: Arg value is Array
55: string(9) "number 1."
56:
57: Arg value is /[a-zA-Z]/
58: string(3) " 1."
59: ===Done===
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>