xref: /PHP-7.0/ext/pcre/tests/004.phpt (revision cb9c99eb)
1--TEST--
2abusing pcre
3--FILE--
4<?php
5
6var_dump(preg_match_all('/((?:(?:unsigned|struct)\s+)?\w+)(?:\s*(\*+)\s+|\s+(\**))(\w+(?:\[\s*\w*\s*\])?)\s*(?:(=)[^,;]+)?((?:\s*,\s*\**\s*\w+(?:\[\s*\w*\s*\])?\s*(?:=[^,;]+)?)*)\s*;/S', 'unsigned int xpto = 124; short a, b;', $m, PREG_SET_ORDER));
7var_dump($m);
8
9var_dump(preg_match_all('/(?:\([^)]+\))?(&?)([\w>.()-]+(?:\[\w+\])?)\s*,?((?:\)*\s*=)?)/S', '&a, b, &c', $m, PREG_SET_ORDER));
10var_dump($m);
11
12var_dump(preg_match_all('/zend_parse_parameters(?:_ex\s*\([^,]+,[^,]+|\s*\([^,]+),\s*"([^"]*)"\s*,\s*([^{;]*)/S', 'zend_parse_parameters( 0, "addd|s/", a, b, &c);', $m, PREG_SET_ORDER | PREG_OFFSET_CAPTURE));
13var_dump($m);
14
15var_dump(preg_split('/PHP_(?:NAMED_)?(?:FUNCTION|METHOD)\s*\((\w+(?:,\s*\w+)?)\)/S', "PHP_FUNCTION(s, preg_match)\n{\nlalala", -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_OFFSET_CAPTURE));
16?>
17--EXPECTF--
18int(2)
19array(2) {
20  [0]=>
21  array(7) {
22    [0]=>
23    string(24) "unsigned int xpto = 124;"
24    [1]=>
25    string(12) "unsigned int"
26    [2]=>
27    string(0) ""
28    [3]=>
29    string(0) ""
30    [4]=>
31    string(4) "xpto"
32    [5]=>
33    string(1) "="
34    [6]=>
35    string(0) ""
36  }
37  [1]=>
38  array(7) {
39    [0]=>
40    string(11) "short a, b;"
41    [1]=>
42    string(5) "short"
43    [2]=>
44    string(0) ""
45    [3]=>
46    string(0) ""
47    [4]=>
48    string(1) "a"
49    [5]=>
50    string(0) ""
51    [6]=>
52    string(3) ", b"
53  }
54}
55int(3)
56array(3) {
57  [0]=>
58  array(4) {
59    [0]=>
60    string(3) "&a,"
61    [1]=>
62    string(1) "&"
63    [2]=>
64    string(1) "a"
65    [3]=>
66    string(0) ""
67  }
68  [1]=>
69  array(4) {
70    [0]=>
71    string(2) "b,"
72    [1]=>
73    string(0) ""
74    [2]=>
75    string(1) "b"
76    [3]=>
77    string(0) ""
78  }
79  [2]=>
80  array(4) {
81    [0]=>
82    string(2) "&c"
83    [1]=>
84    string(1) "&"
85    [2]=>
86    string(1) "c"
87    [3]=>
88    string(0) ""
89  }
90}
91int(1)
92array(1) {
93  [0]=>
94  array(3) {
95    [0]=>
96    array(2) {
97      [0]=>
98      string(46) "zend_parse_parameters( 0, "addd|s/", a, b, &c)"
99      [1]=>
100      int(0)
101    }
102    [1]=>
103    array(2) {
104      [0]=>
105      string(7) "addd|s/"
106      [1]=>
107      int(27)
108    }
109    [2]=>
110    array(2) {
111      [0]=>
112      string(9) "a, b, &c)"
113      [1]=>
114      int(37)
115    }
116  }
117}
118array(3) {
119  [0]=>
120  array(2) {
121    [0]=>
122    string(0) ""
123    [1]=>
124    int(0)
125  }
126  [1]=>
127  array(2) {
128    [0]=>
129    string(13) "s, preg_match"
130    [1]=>
131    int(13)
132  }
133  [2]=>
134  array(2) {
135    [0]=>
136    string(9) "
137{
138lalala"
139    [1]=>
140    int(27)
141  }
142}
143