- Deprecated mysql_list_dbs() (Request #50667). (Andrey)
+- Implemented FR #53238 (Make third parameter of preg_match_all optional).
+ (Adam)
- Implemented FR #52555 (Ability to get HTTP response code). (Paul Dragoonis)
- Implemented FR #51295 (SQLite3::busyTimeout not existing). (Mark)
- Implemented FR #49366 (Make slash escaping optional in json_encode()). (Adam)
behavior follows the recommendations of Unicode Technical Report #36.
- htmlspecialchars_decode/html_entity_decode now decode ' if the document
type is ENT_XML1, ENT_XHTML, or ENT_HTML5.
+- The third parameter ($matches) to preg_match_all() is now optional. If
+ omitted, the function will simply return the number of times the pattern was
+ matched in the subject and will have no other side effects.
===================================
long flags = 0; /* Match control flags */
long start_offset = 0; /* Where the new search starts */
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, ((global) ? "ssz|ll" : "ss|zll"), ®ex, ®ex_len,
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|zll", ®ex, ®ex_len,
&subject, &subject_len, &subpats, &flags, &start_offset) == FAILURE) {
RETURN_FALSE;
}
offsets = (int *)safe_emalloc(size_offsets, sizeof(int), 0);
/* Allocate match sets array and initialize the values. */
- if (global && subpats_order == PREG_PATTERN_ORDER) {
+ if (global && subpats && subpats_order == PREG_PATTERN_ORDER) {
match_sets = (zval **)safe_emalloc(num_subpats, sizeof(zval *), 0);
for (i=0; i<num_subpats; i++) {
ALLOC_ZVAL(match_sets[i]);
}
if (global) { /* global pattern matching */
- if (subpats_order == PREG_PATTERN_ORDER) {
+ if (subpats && subpats_order == PREG_PATTERN_ORDER) {
/* For each subpattern, insert it into the appropriate array. */
for (i = 0; i < count; i++) {
if (offset_capture) {
} while (global);
/* Add the match sets to the output array and clean up */
- if (global && subpats_order == PREG_PATTERN_ORDER) {
+ if (global && subpats && subpats_order == PREG_PATTERN_ORDER) {
for (i = 0; i < num_subpats; i++) {
if (subpat_names[i]) {
zend_hash_update(Z_ARRVAL_P(subpats), subpat_names[i],
}
/* }}} */
-/* {{{ proto int preg_match_all(string pattern, string subject, array &subpatterns [, int flags [, int offset]])
+/* {{{ proto int preg_match_all(string pattern, string subject, [array &subpatterns [, int flags [, int offset]]])
Perform a Perl-style global regular expression match */
static PHP_FUNCTION(preg_match_all)
{
Warning: preg_match() expects at least 2 parameters, 0 given in %s002.php on line 3
bool(false)
-Warning: preg_match_all() expects at least 3 parameters, 0 given in %s002.php on line 4
+Warning: preg_match_all() expects at least 2 parameters, 0 given in %s002.php on line 4
bool(false)
Warning: preg_match_all(): Invalid flags specified in %s002.php on line 5
--FILE--
<?php
/*
-* proto int preg_match_all(string pattern, string subject, array subpatterns [, int flags [, int offset]])
+* proto int preg_match_all(string pattern, string subject, [array subpatterns [, int flags [, int offset]]])
* Function is implemented in ext/pcre/php_pcre.c
*/
$string = 'Hello, world! This is a test. This is another test. \[4]. 34534 string.';
var_dump($match4);
var_dump(preg_match_all('/(This is a ){2}(.*)\stest/', $string, $match5)); //tries to find "This is aThis is a [...] test" (0 matches)
var_dump($match5);
+
+// Test not passing in a subpatterns array.
+var_dump(preg_match_all('/test/', $string));
+var_dump(preg_match_all('/this isn\'t in the string/', $string));
+var_dump(preg_match_all('/world/', $string));
+var_dump(preg_match_all('/[0-9]/', $string));
?>
--EXPECTF--
int(1)
array(0) {
}
}
+int(2)
+int(0)
+int(1)
+int(6)
// Testing preg_match_all withone less than the expected number of arguments
echo "\n-- Testing preg_match_all() function with less than expected no. of arguments --\n";
$pattern = '/\w/';
-$subject = 'string_val';
-var_dump(preg_match_all($pattern, $subject));
+var_dump(preg_match_all($pattern));
echo "Done"
?>
--EXPECTF--
-- Testing preg_match_all() function with Zero arguments --
-Warning: preg_match_all() expects at least 3 parameters, 0 given in %spreg_match_all_error.php on line %d
+Warning: preg_match_all() expects at least 2 parameters, 0 given in %spreg_match_all_error.php on line %d
bool(false)
-- Testing preg_match_all() function with more than expected no. of arguments --
-- Testing preg_match_all() function with less than expected no. of arguments --
-Warning: preg_match_all() expects at least 3 parameters, 2 given in %spreg_match_all_error.php on line %d
+Warning: preg_match_all() expects at least 2 parameters, 1 given in %spreg_match_all_error.php on line %d
bool(false)
Done