php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #53238 Make third parameter of preg_match_all optional
Submitted: 2010-11-03 19:32 UTC Modified: 2010-11-05 19:18 UTC
From: giovanni at giacobbi dot net Assigned: aharvey
Status: Closed Package: PCRE related
PHP Version: 5.3.3 OS: any
Private report: No CVE-ID:
 [2010-11-03 19:32 UTC] giovanni at giacobbi dot net
Description:
------------
I had to count the time a regular expression is in a string, and the correct way to do this is with the return value of preg_match_all() because preg_match() will always return either 0 or 1.
The problem is that preg_match_all() enforces the third parameter. My request is to align the prototype of preg_match_all() to the one of preg_match(), i.e. making the third parameter optional.


Test script:
---------------
$cnt = preg_match_all('/<br\s*\/?>/i', "this<br/>my<br>text");
var_dump($cnt);


Expected result:
----------------
int(2)


Actual result:
--------------
Warning: preg_match_all() expects at least 3 parameters, 2 given in - on line 2
bool(false)


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-11-05 05:23 UTC] aharvey@php.net
-Status: Open +Status: Assigned -Assigned To: +Assigned To: aharvey
 [2010-11-05 05:37 UTC] aharvey@php.net
Automatic comment from SVN on behalf of aharvey
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=305097
Log: Implemented FR #53238 (Make third parameter of preg_match_all optional).
 [2010-11-05 05:37 UTC] aharvey@php.net
-Status: Assigned +Status: Closed
 [2010-11-05 05:37 UTC] aharvey@php.net
This bug has been fixed in SVN.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.

This has been implemented on trunk, and should be in 5.4. (Assuming that's what it's called.)
 [2010-11-05 15:00 UTC] giovanni at giacobbi dot net
Hi aharvey, thank you for the extremely quick reaction. Two things:

I think you misplaced the [, it's supposed to go in front of the comma:

-/* {{{ 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]]])

second thing is.. any chance to have this backported for 5.3.4? There is no BC break since it's a parameter that becomes optional. I understand if you want to keep all API changes for minor version, it's what I would do as well..only problem with PHP is that it has a too slow release cycle.

Thank you anyway, I really appreciate your support.
 [2010-11-05 19:18 UTC] aharvey@php.net
Good catch on the bracket. Fixed, and thanks. :)

It probably wouldn't be hard to backport this to the 5.3 branch, but my inclination is to leave this only in trunk for now -- we're likely to have the first RC for 5.3.4 in less than two weeks, and I don't see this being important enough to shoehorn it into 5.3 to make that release in particular. We'll get some more testing on this (hopefully) in a 5.4 alpha fairly soon, too.

I'm happy enough to have another look at this for 5.3 after 5.3.4 is done, though. Feel free to prod me via e-mail or the bug tracker if I forget. :)
 [2010-11-05 21:20 UTC] giovanni at giacobbi dot net
Agreed on everything! The only thing, if you decide to leave it out for 5.3.4 the 
leave it out forever! In general, if you do this with all features, people will 
migrate to 5.4 more easily because the stuff they want is there...otherwise will 
happen again the same between 5.2 and 5.3.

Thank you! bye
 
PHP Copyright © 2001-2014 The PHP Group
All rights reserved.
Last updated: Thu Apr 17 03:01:55 2014 UTC