Test Setup Failed
Pull Request — master (#216)
by Viruthagiri
05:38
created

testXMLParser::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 8
rs 9.4285
cc 1
eloc 7
nc 1
nop 1
1
<?php
2
3
// misc help functions and utilities
4
5
function rand_str($len=32) {
6
	return substr(md5(uniqid(rand())), 0, $len);
7
}
8
9
// strip leading and trailing whitespace from each line in the string
10
function strip_ws($txt) {
11
	$lines = explode("\n", $txt);
12
	$result = array();
13
	foreach ($lines as $line)
14
		if (trim($line))
15
			$result[] = trim($line);
16
17
	return trim(join("\n", $result));
18
}
19
20
// helper class for testing code that involves actions and filters
0 ignored issues
show
Unused Code Comprehensibility introduced by
40% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
21
// typical use:
22
// $ma = new MockAction();
23
// add_action('foo', array(&$ma, 'action'));
24
class MockAction {
25
	var $events;
26
	var $debug;
27
28
	/**
29
	 * PHP5 constructor.
30
	 */
31
	function __construct( $debug = 0 ) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
32
		$this->reset();
33
		$this->debug = $debug;
34
	}
35
36
	function reset() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
37
		$this->events = array();
38
	}
39
40
	function current_filter() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
41
		if (is_callable('current_filter'))
42
			return current_filter();
43
		global $wp_actions;
44
		return end($wp_actions);
45
	}
46
47 View Code Duplication
	function action($arg) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
48
if ($this->debug) dmp(__FUNCTION__, $this->current_filter());
49
		$args = func_get_args();
50
		$this->events[] = array('action' => __FUNCTION__, 'tag'=>$this->current_filter(), 'args'=>$args);
51
		return $arg;
52
	}
53
54 View Code Duplication
	function action2($arg) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
55
if ($this->debug) dmp(__FUNCTION__, $this->current_filter());
56
57
		$args = func_get_args();
58
		$this->events[] = array('action' => __FUNCTION__, 'tag'=>$this->current_filter(), 'args'=>$args);
59
		return $arg;
60
	}
61
62 View Code Duplication
	function filter($arg) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
63
if ($this->debug) dmp(__FUNCTION__, $this->current_filter());
64
65
		$args = func_get_args();
66
		$this->events[] = array('filter' => __FUNCTION__, 'tag'=>$this->current_filter(), 'args'=>$args);
67
		return $arg;
68
	}
69
70 View Code Duplication
	function filter2($arg) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
71
if ($this->debug) dmp(__FUNCTION__, $this->current_filter());
72
73
		$args = func_get_args();
74
		$this->events[] = array('filter' => __FUNCTION__, 'tag'=>$this->current_filter(), 'args'=>$args);
75
		return $arg;
76
	}
77
78 View Code Duplication
	function filter_append($arg) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
79
if ($this->debug) dmp(__FUNCTION__, $this->current_filter());
80
81
		$args = func_get_args();
82
		$this->events[] = array('filter' => __FUNCTION__, 'tag'=>$this->current_filter(), 'args'=>$args);
83
		return $arg . '_append';
84
	}
85
86
	function filterall($tag, $arg=NULL) {
0 ignored issues
show
Unused Code introduced by
The parameter $arg is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
87
	// this one doesn't return the result, so it's safe to use with the new 'all' filter
88
if ($this->debug) dmp(__FUNCTION__, $this->current_filter());
89
90
		$args = func_get_args();
91
		$this->events[] = array('filter' => __FUNCTION__, 'tag'=>$tag, 'args'=>array_slice($args, 1));
92
	}
93
94
	// return a list of all the actions, tags and args
95
	function get_events() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
96
		return $this->events;
97
	}
98
99
	// return a count of the number of times the action was called since the last reset
100
	function get_call_count($tag='') {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
101
		if ($tag) {
102
			$count = 0;
103
			foreach ($this->events as $e)
104
				if ($e['action'] == $tag)
105
					++$count;
106
			return $count;
107
		}
108
		return count($this->events);
109
	}
110
111
	// return an array of the tags that triggered calls to this action
112
	function get_tags() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
113
		$out = array();
114
		foreach ($this->events as $e) {
115
			$out[] = $e['tag'];
116
		}
117
		return $out;
118
	}
119
120
	// return an array of args passed in calls to this action
121
	function get_args() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
122
		$out = array();
123
		foreach ($this->events as $e)
124
			$out[] = $e['args'];
125
		return $out;
126
	}
127
}
128
129
// convert valid xml to an array tree structure
130
// kinda lame but it works with a default php 4 install
131
class testXMLParser {
132
	var $xml;
133
	var $data = array();
134
135
	/**
136
	 * PHP5 constructor.
137
	 */
138
	function __construct( $in ) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
139
		$this->xml = xml_parser_create();
140
		xml_set_object($this->xml, $this);
141
		xml_parser_set_option($this->xml,XML_OPTION_CASE_FOLDING, 0);
142
		xml_set_element_handler($this->xml, array($this, 'startHandler'), array($this, 'endHandler'));
143
		xml_set_character_data_handler($this->xml, array($this, 'dataHandler'));
144
		$this->parse($in);
145
	}
146
147
	function parse($in) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
148
		$parse = xml_parse($this->xml, $in, sizeof($in));
149
		if (!$parse) {
150
			trigger_error(sprintf("XML error: %s at line %d",
151
			xml_error_string(xml_get_error_code($this->xml)),
152
			xml_get_current_line_number($this->xml)), E_USER_ERROR);
153
			xml_parser_free($this->xml);
154
		}
155
		return true;
156
	}
157
158
	function startHandler($parser, $name, $attributes) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
159
		$data['name'] = $name;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$data was never initialized. Although not strictly required by PHP, it is generally a good practice to add $data = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
160
		if ($attributes) { $data['attributes'] = $attributes; }
161
		$this->data[] = $data;
162
	}
163
164
	function dataHandler($parser, $data) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
165
		$index = count($this->data) - 1;
166
		@$this->data[$index]['content'] .= $data;
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
167
	}
168
169
	function endHandler($parser, $name) {
0 ignored issues
show
Unused Code introduced by
The parameter $parser is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $name is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
170
		if (count($this->data) > 1) {
171
			$data = array_pop($this->data);
172
			$index = count($this->data) - 1;
173
			$this->data[$index]['child'][] = $data;
174
		}
175
	}
176
}
177
178
function xml_to_array($in) {
179
	$p = new testXMLParser($in);
180
	return $p->data;
0 ignored issues
show
Bug introduced by
The property data cannot be accessed from this context as it is declared private in class testXMLParser.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
181
}
182
183
function xml_find($tree /*, $el1, $el2, $el3, .. */) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
54% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
184
	$a = func_get_args();
185
	$a = array_slice($a, 1);
186
	$n = count($a);
187
	$out = array();
188
189
	if ($n < 1)
190
		return $out;
191
192
	for ($i=0; $i<count($tree); $i++) {
0 ignored issues
show
Performance Best Practice introduced by
It seems like you are calling the size function count() as part of the test condition. You might want to compute the size beforehand, and not on each iteration.

If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration:

for ($i=0; $i<count($array); $i++) { // calls count() on each iteration
}

// Better
for ($i=0, $c=count($array); $i<$c; $i++) { // calls count() just once
}
Loading history...
193
#		echo "checking '{$tree[$i][name]}' == '{$a[0]}'\n";
0 ignored issues
show
Unused Code Comprehensibility introduced by
75% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
194
#		var_dump($tree[$i]['name'], $a[0]);
195
		if ($tree[$i]['name'] == $a[0]) {
196
#			echo "n == {$n}\n";
197
			if ($n == 1)
198
				$out[] = $tree[$i];
199
			else {
200
				$subtree =& $tree[$i]['child'];
201
				$call_args = array($subtree);
202
				$call_args = array_merge($call_args, array_slice($a, 1));
203
				$out = array_merge($out, call_user_func_array('xml_find', $call_args));
204
			}
205
		}
206
	}
207
208
	return $out;
209
}
210
211
function xml_join_atts($atts) {
212
	$a = array();
213
	foreach ($atts as $k=>$v)
214
		$a[] = $k.'="'.$v.'"';
215
	return join(' ', $a);
216
}
217
218
function xml_array_dumbdown(&$data) {
219
	$out = array();
220
221
	foreach (array_keys($data) as $i) {
222
		$name = $data[$i]['name'];
223
		if (!empty($data[$i]['attributes']))
224
			$name .= ' '.xml_join_atts($data[$i]['attributes']);
225
226
		if (!empty($data[$i]['child'])) {
227
			$out[$name][] = xml_array_dumbdown($data[$i]['child']);
228
		}
229
		else
230
			$out[$name] = $data[$i]['content'];
231
	}
232
233
	return $out;
234
}
235
236
function dmp() {
237
	$args = func_get_args();
238
239
	foreach ($args as $thing)
240
		echo (is_scalar($thing) ? strval($thing) : var_export($thing, true)), "\n";
241
}
242
243
function dmp_filter($a) {
244
	dmp($a);
245
	return $a;
246
}
247
248
function get_echo($callable, $args = array()) {
249
	ob_start();
250
	call_user_func_array($callable, $args);
251
	return ob_get_clean();
252
}
253
254
// recursively generate some quick assertEquals tests based on an array
255
function gen_tests_array($name, $array) {
256
	$out = array();
257
	foreach ($array as $k=>$v) {
258
		if (is_numeric($k))
259
			$index = strval($k);
260
		else
261
			$index = "'".addcslashes($k, "\n\r\t'\\")."'";
262
263
		if (is_string($v)) {
264
			$out[] = '$this->assertEquals( \'' . addcslashes($v, "\n\r\t'\\") . '\', $'.$name.'['.$index.'] );';
265
		}
266
		elseif (is_numeric($v)) {
267
			$out[] = '$this->assertEquals( ' . $v . ', $'.$name.'['.$index.'] );';
268
		}
269
		elseif (is_array($v)) {
270
			$out[] = gen_tests_array("{$name}[{$index}]", $v);
271
		}
272
	}
273
	return join("\n", $out)."\n";
274
}
275
276
/**
277
 * Use to create objects by yourself
278
 */
279
class MockClass {};
280
281
/**
282
 * Drops all tables from the WordPress database
283
 */
284
function drop_tables() {
285
	global $wpdb;
286
	$tables = $wpdb->get_col('SHOW TABLES;');
287
	foreach ($tables as $table)
288
		$wpdb->query("DROP TABLE IF EXISTS {$table}");
289
}
290
291
function print_backtrace() {
292
	$bt = debug_backtrace();
293
	echo "Backtrace:\n";
294
	$i = 0;
295
	foreach ($bt as $stack) {
296
		echo ++$i, ": ";
297
		if ( isset($stack['class']) )
298
			echo $stack['class'].'::';
299
		if ( isset($stack['function']) )
300
			echo $stack['function'].'() ';
301
		echo "line {$stack[line]} in {$stack[file]}\n";
302
	}
303
	echo "\n";
304
}
305
306
// mask out any input fields matching the given name
307
function mask_input_value($in, $name='_wpnonce') {
308
	return preg_replace('@<input([^>]*) name="'.preg_quote($name).'"([^>]*) value="[^>]*" />@', '<input$1 name="'.preg_quote($name).'"$2 value="***" />', $in);
309
}
310
311
if ( !function_exists( 'str_getcsv' ) ) {
312
	function str_getcsv( $input, $delimiter = ',', $enclosure = '"', $escape = "\\" ) {
0 ignored issues
show
Unused Code introduced by
The parameter $escape is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
313
		$fp = fopen( 'php://temp/', 'r+' );
314
		fputs( $fp, $input );
315
		rewind( $fp );
316
		$data = fgetcsv( $fp, strlen( $input ), $delimiter, $enclosure );
317
		fclose( $fp );
318
		return $data;
319
	}
320
}
321
322
/**
323
 * Removes the post type and its taxonomy associations.
324
 */
325
function _unregister_post_type( $cpt_name ) {
326
	unset( $GLOBALS['wp_post_types'][ $cpt_name ] );
327
	unset( $GLOBALS['_wp_post_type_features'][ $cpt_name ] );
328
329
	foreach ( $GLOBALS['wp_taxonomies'] as $taxonomy ) {
330
		if ( false !== $key = array_search( $cpt_name, $taxonomy->object_type ) ) {
331
			unset( $taxonomy->object_type[$key] );
332
		}
333
	}
334
}
335
336
function _unregister_taxonomy( $taxonomy_name ) {
337
	unset( $GLOBALS['wp_taxonomies'][$taxonomy_name] );
338
}
339
340
/**
341
 * Unregister a post status.
342
 *
343
 * @since 4.2.0
344
 *
345
 * @param string $status
346
 */
347
function _unregister_post_status( $status ) {
348
	unset( $GLOBALS['wp_post_statuses'][ $status ] );
349
}
350
351
function _cleanup_query_vars() {
352
	// clean out globals to stop them polluting wp and wp_query
353
	foreach ( $GLOBALS['wp']->public_query_vars as $v )
354
		unset( $GLOBALS[$v] );
355
356
	foreach ( $GLOBALS['wp']->private_query_vars as $v )
357
		unset( $GLOBALS[$v] );
358
359
	foreach ( get_taxonomies( array() , 'objects' ) as $t ) {
360
		if ( $t->public && ! empty( $t->query_var ) )
361
			$GLOBALS['wp']->add_query_var( $t->query_var );
362
	}
363
364
	foreach ( get_post_types( array() , 'objects' ) as $t ) {
365
		if ( is_post_type_viewable( $t ) && ! empty( $t->query_var ) )
366
			$GLOBALS['wp']->add_query_var( $t->query_var );
367
	}
368
}
369
370
function _clean_term_filters() {
371
	remove_filter( 'get_terms',     array( 'Featured_Content', 'hide_featured_term'     ), 10, 2 );
372
	remove_filter( 'get_the_terms', array( 'Featured_Content', 'hide_the_featured_term' ), 10, 3 );
373
}
374
375
/**
376
 * Special class for exposing protected wpdb methods we need to access
377
 */
378
class wpdb_exposed_methods_for_testing extends wpdb {
379
	public function __construct() {
380
		global $wpdb;
381
		$this->dbh = $wpdb->dbh;
382
		$this->use_mysqli = $wpdb->use_mysqli;
383
		$this->is_mysql = $wpdb->is_mysql;
384
		$this->ready = true;
385
		$this->field_types = $wpdb->field_types;
386
		$this->charset = $wpdb->charset;
387
	}
388
389
	public function __call( $name, $arguments ) {
390
		return call_user_func_array( array( $this, $name ), $arguments );
391
	}
392
}
393
394
/**
395
 * Determine approximate backtrack count when running PCRE.
396
 *
397
 * @return int The backtrack count.
398
 */
399
function benchmark_pcre_backtracking( $pattern, $subject, $strategy ) {
400
	$saved_config = ini_get( 'pcre.backtrack_limit' );
401
	
402
	// Attempt to prevent PHP crashes.  Adjust these lower when needed.
403
	if ( version_compare( phpversion(), '5.4.8', '>' ) ) {
404
		$limit = 1000000;
405
	} else {
406
		$limit = 20000;  // 20,000 is a reasonable upper limit, but see also https://core.trac.wordpress.org/ticket/29557#comment:10
407
	}
408
409
	// Start with small numbers, so if a crash is encountered at higher numbers we can still debug the problem.
410
	for( $i = 4; $i <= $limit; $i *= 2 ) {
411
412
		ini_set( 'pcre.backtrack_limit', $i );
413
		
414
		switch( $strategy ) {
415
		case 'split':
416
			preg_split( $pattern, $subject );
417
			break;
418
		case 'match':
419
			preg_match( $pattern, $subject );
420
			break;
421
		case 'match_all':
422
			$matches = array();
423
			preg_match_all( $pattern, $subject, $matches );
424
			break;
425
		}
426
427
		ini_set( 'pcre.backtrack_limit', $saved_config );
428
429
		switch( preg_last_error() ) {
430
		case PREG_NO_ERROR:
431
			return $i;
432
		case PREG_BACKTRACK_LIMIT_ERROR:
433
			continue;
434
		case PREG_RECURSION_LIMIT_ERROR:
435
			trigger_error('PCRE recursion limit encountered before backtrack limit.');
436
			return;
437
		case PREG_BAD_UTF8_ERROR:
438
			trigger_error('UTF-8 error during PCRE benchmark.');
439
			return;
440
		case PREG_INTERNAL_ERROR:
441
			trigger_error('Internal error during PCRE benchmark.');
442
			return;
443
		default:
444
			trigger_error('Unexpected error during PCRE benchmark.');
445
			return;
446
		}
447
	}
448
449
	return $i;
450
}
451