svn: /php/php-src/trunk/ NEWS UPGRADING ext/pcre/php_pcre.c ext/pcre/tests/002.phpt ext/pcre/tests/preg_match_all_basic.phpt
ext/pcre/tests/preg_match_all_error.phpt
| From: | Adam Harvey | Date: | Fri, 05 Nov 2010 04:37:27 +0000 |
| Subject: | svn: /php/php-src/trunk/ NEWS UPGRADING ext/pcre/php_pcre.c ext/pcre/tests/002.phpt ext/pcre/tests/preg_match_all_basic.phpt ext/pcre/tests/preg_match_all_error.phpt |
||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-63760@lists.php.net to get a copy of this message | ||
aharvey Fri, 05 Nov 2010 04:37:27 +0000
Revision: http://svn.php.net/viewvc?view=revision&revision=305097
Log:
Implemented FR #53238 (Make third parameter of preg_match_all optional).
Bug: http://bugs.php.net/53238 (Assigned) Make third
parameter of preg_match_all optional
Changed paths:
U php/php-src/trunk/NEWS
U php/php-src/trunk/UPGRADING
U php/php-src/trunk/ext/pcre/php_pcre.c
U php/php-src/trunk/ext/pcre/tests/002.phpt
U php/php-src/trunk/ext/pcre/tests/preg_match_all_basic.phpt
U php/php-src/trunk/ext/pcre/tests/preg_match_all_error.phpt
Modified: php/php-src/trunk/NEWS
===================================================================
--- php/php-src/trunk/NEWS 2010-11-05 01:56:28 UTC (rev 305096)
+++ php/php-src/trunk/NEWS 2010-11-05 04:37:27 UTC (rev 305097)
@@ -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)
Modified: php/php-src/trunk/UPGRADING
===================================================================
--- php/php-src/trunk/UPGRADING 2010-11-05 01:56:28 UTC (rev 305096)
+++ php/php-src/trunk/UPGRADING 2010-11-05 04:37:27 UTC (rev 305097)
@@ -133,6 +133,9 @@
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.
===================================
Modified: php/php-src/trunk/ext/pcre/php_pcre.c
===================================================================
--- php/php-src/trunk/ext/pcre/php_pcre.c 2010-11-05 01:56:28 UTC (rev 305096)
+++ php/php-src/trunk/ext/pcre/php_pcre.c 2010-11-05 04:37:27 UTC (rev 305097)
@@ -506,7 +506,7 @@
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 @@
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]);
@@ -649,7 +649,7 @@
}
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) {
@@ -739,7 +739,7 @@
} 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],
@@ -766,7 +766,7 @@
}
/* }}} */
-/* {{{ 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)
{
Modified: php/php-src/trunk/ext/pcre/tests/002.phpt
===================================================================
--- php/php-src/trunk/ext/pcre/tests/002.phpt 2010-11-05 01:56:28 UTC (rev 305096)
+++ php/php-src/trunk/ext/pcre/tests/002.phpt 2010-11-05 04:37:27 UTC (rev 305097)
@@ -20,7 +20,7 @@
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
Modified: php/php-src/trunk/ext/pcre/tests/preg_match_all_basic.phpt
===================================================================
--- php/php-src/trunk/ext/pcre/tests/preg_match_all_basic.phpt 2010-11-05 01:56:28 UTC (rev 305096)
+++ php/php-src/trunk/ext/pcre/tests/preg_match_all_basic.phpt 2010-11-05 04:37:27 UTC (rev 305097)
@@ -3,7 +3,7 @@
--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.';
@@ -17,6 +17,12 @@
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)
@@ -80,3 +86,7 @@
array(0) {
}
}
+int(2)
+int(0)
+int(1)
+int(6)
Modified: php/php-src/trunk/ext/pcre/tests/preg_match_all_error.phpt
===================================================================
--- php/php-src/trunk/ext/pcre/tests/preg_match_all_error.phpt 2010-11-05 01:56:28 UTC (rev 305096)
+++ php/php-src/trunk/ext/pcre/tests/preg_match_all_error.phpt 2010-11-05 04:37:27 UTC (rev 305097)
@@ -21,8 +21,7 @@
// 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 @@
-- 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 @@
-- 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