From 83657396630f792b784828f36ac4ac39e26cf674 Mon Sep 17 00:00:00 2001 From: Adam Harvey Date: Fri, 5 Nov 2010 04:37:27 +0000 Subject: [PATCH] Implemented FR #53238 (Make third parameter of preg_match_all optional). --- NEWS | 2 ++ UPGRADING | 3 +++ ext/pcre/php_pcre.c | 10 +++++----- ext/pcre/tests/002.phpt | 2 +- ext/pcre/tests/preg_match_all_basic.phpt | 12 +++++++++++- ext/pcre/tests/preg_match_all_error.phpt | 7 +++---- 6 files changed, 25 insertions(+), 11 deletions(-) diff --git a/NEWS b/NEWS index 47d2f6dfc3..abf454a5dc 100644 --- a/NEWS +++ b/NEWS @@ -121,6 +121,8 @@ - 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) diff --git a/UPGRADING b/UPGRADING index abaf7baf52..336f37f038 100755 --- a/UPGRADING +++ b/UPGRADING @@ -133,6 +133,9 @@ UPGRADE NOTES - PHP X.Y 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. =================================== diff --git a/ext/pcre/php_pcre.c b/ext/pcre/php_pcre.c index ccb0a51c0e..ce0549fb73 100644 --- a/ext/pcre/php_pcre.c +++ b/ext/pcre/php_pcre.c @@ -506,7 +506,7 @@ static void php_do_pcre_match(INTERNAL_FUNCTION_PARAMETERS, int global) /* {{{ * 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; } @@ -608,7 +608,7 @@ PHPAPI void php_pcre_match_impl(pcre_cache_entry *pce, char *subject, int subjec 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 --EXPECTF-- int(1) @@ -80,3 +86,7 @@ array(3) { array(0) { } } +int(2) +int(0) +int(1) +int(6) diff --git a/ext/pcre/tests/preg_match_all_error.phpt b/ext/pcre/tests/preg_match_all_error.phpt index 2371ccfef1..f6e89284bb 100644 --- a/ext/pcre/tests/preg_match_all_error.phpt +++ b/ext/pcre/tests/preg_match_all_error.phpt @@ -21,8 +21,7 @@ var_dump(preg_match_all($pattern, $subject, $matches, $flags, $offset, $extra_ar // 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-- @@ -30,7 +29,7 @@ echo "Done" -- 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 -- @@ -40,6 +39,6 @@ bool(false) -- 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 -- 2.40.0