Skip to content

Commit 06dde16

Browse files
Sean-Dernikic
authored andcommitted
Update scripts/dev/check_parameters.php for PHP 7
Also fix deprecation errors and move from preg_replace -> preg_replace_callback.
1 parent 8557e83 commit 06dde16

File tree

1 file changed

+22
-40
lines changed

1 file changed

+22
-40
lines changed

scripts/dev/check_parameters.php

Lines changed: 22 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222

2323
define('REPORT_LEVEL', 2); // 0 reports less false-positives. up to level 5.
24-
define('VERSION', '5.2'); // minimum is 5.2
24+
define('VERSION', '7.0'); // minimum is 7.0
2525
define('PHPDIR', realpath(dirname(__FILE__) . '/../..'));
2626

2727

@@ -33,39 +33,35 @@
3333

3434

3535
$API_params = array(
36-
'a' => array('zval**'), // array as zval*
36+
'a' => array('zval**'), // array
37+
'A' => array('zval**'), // array or object
3738
'b' => array('zend_bool*'), // boolean
3839
'C' => array('zend_class_entry**'), // class
3940
'd' => array('double*'), // double
4041
'f' => array('zend_fcall_info*', 'zend_fcall_info_cache*'), // function
4142
'h' => array('HashTable**'), // array as an HashTable*
42-
'l' => array('long*'), // long
43+
'H' => array('HashTable**'), // array or HASH_OF(object)
44+
'l' => array('zend_long*'), // long
45+
//TODO 'L' => array('zend_long*, '), // long
4346
'o' => array('zval**'), //object
4447
'O' => array('zval**', 'zend_class_entry*'), // object of given type
48+
'p' => array('char**', 'size_t*'), // valid path
49+
'P' => array('zend_string**'), // valid path
4550
'r' => array('zval**'), // resource
46-
's' => array('char**', 'int*'), // string
51+
's' => array('char**', 'size_t*'), // string
52+
'S' => array('zend_string**'), // string
4753
'z' => array('zval**'), // zval*
4854
'Z' => array('zval***') // zval**
4955
);
5056

51-
// specific to PHP >= 6
52-
if (version_compare(VERSION, '6', 'ge')) {
53-
$API_params['S'] = $API_params['s']; // binary string
54-
$API_params['t'] = array('zstr*', 'int*', 'zend_uchar*'); // text
55-
$API_params['T'] = $API_params['t'];
56-
$API_params['u'] = array('UChar**', 'int*'); // unicode
57-
$API_params['U'] = $API_params['u'];
58-
}
59-
60-
6157
/** reports an error, according to its level */
6258
function error($str, $level = 0)
6359
{
6460
global $current_file, $current_function, $line;
6561

6662
if ($level <= REPORT_LEVEL) {
6763
if (strpos($current_file,PHPDIR) === 0) {
68-
$filename = substr($current_file, strlen(PHPDIR)+1);
64+
$filename = substr($current_file, strlen(PHPDIR)+1);
6965
} else {
7066
$filename = $current_file;
7167
}
@@ -243,31 +239,15 @@ function check_function($name, $txt, $offset)
243239
}
244240
break;
245241

246-
case '&':
247-
if (version_compare(VERSION, '6', 'ge')) {
248-
if ($last_char == 's' || ($last_last_char == 's' && $last_char == '!')) {
249-
check_param($params, ++$j, 'UConverter*', $optional);
250-
251-
} else {
252-
error("the '&' specifier cannot be applied to '$last_char'");
253-
}
254-
} else {
255-
error("unknown char ('&') at column $i");
256-
}
257-
break;
258-
242+
// variadic arguments
259243
case '+':
260244
case '*':
261-
if (version_compare(VERSION, '6', 'ge')) {
262-
if ($varargs) {
263-
error("A varargs specifier can only be used once. repeated char at column $i");
264-
} else {
265-
check_param($params, ++$j, 'zval****', $optional);
266-
check_param($params, ++$j, 'int*', $optional);
267-
$varargs = true;
268-
}
245+
if ($varargs) {
246+
error("A varargs specifier can only be used once. repeated char at column $i");
269247
} else {
270-
error("unknown char ('$char') at column $i");
248+
check_param($params, ++$j, 'zval**', $optional);
249+
check_param($params, ++$j, 'int*', $optional);
250+
$varargs = true;
271251
}
272252
break;
273253

@@ -306,8 +286,10 @@ function recurse($path)
306286

307287
$txt = file_get_contents($file);
308288
// remove comments (but preserve the number of lines)
309-
$txt = preg_replace(array('@//.*@S', '@/\*.*\*/@SsUe'), array('', 'preg_replace("/[^\r\n]+/S", "", \'$0\')'), $txt);
310-
289+
$txt = preg_replace('@//.*@S', '', $txt);
290+
$txt = preg_replace_callback('@/\*.*\*/@SsU', function($matches) {
291+
return preg_replace("/[^\r\n]+/S", "", $matches[0]);
292+
}, $txt);
311293

312294
$split = preg_split('/PHP_(?:NAMED_)?(?:FUNCTION|METHOD)\s*\((\w+(?:,\s*\w+)?)\)/S', $txt, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_OFFSET_CAPTURE);
313295

@@ -352,7 +334,7 @@ function recurse($path)
352334
for ($i = 1; $i < $argc; $i++) {
353335
$dirs[] = $argv[$i];
354336
}
355-
} else {
337+
} else {
356338
$dirs[] = PHPDIR;
357339
}
358340

0 commit comments

Comments
 (0)