|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #52732 Docs say preg_match() returns FALSE on error, but it returns int(0)
Submitted: 2010-08-29 19:42 UTC Modified: 2010-11-06 19:32 UTC
From: drew at dinomite dot net Assigned: felipe (profile)
Status: Closed Package: PCRE related
PHP Version: 5.3.3 OS: Any
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem:
27 - 14 = ?
Subscribe to this entry?

 [2010-08-29 19:42 UTC] drew at dinomite dot net
The documentation states that preg_match() will return the number of matches (0 or 
1) or bool(false) on error.  The latter doesn't happen—preg_match() is returning 
int(0) when an error occurs.

Test script:
// Ensure we hit the backtrack limit
ini_set('pcre.backtrack_limit', 1);

// See
$ret = preg_match('/(?:\D+|<\d+>)*[!?]/', 'foobar foobar foobar');

echo 'Return value is ';

if ($ret === false) {
    echo '$ret is false; preg_last_error() says: ' . preg_last_error() . "\n";
} else {
    echo '$ret is not false; preg_last_error() says: ' . preg_last_error() . "\n";

Expected result:
Return value is bool(false)
$ret is false; preg_last_error() says: 2

Actual result:
Return value is int(0)
$ret is not false; preg_last_error() says: 2


preg_match_false_on_error (last revision 2010-10-07 13:39 UTC by slugonamission at gmail dot com)
Bug_52732_preg_match_false_on_error (last revision 2010-10-07 13:37 UTC by slugonamission at gmail dot com)

Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2010-11-06 19:32 UTC]
Automatic comment from SVN on behalf of felipe
Log: - Fixed bug #52732 (Docs say preg_match() returns FALSE on error, but it returns int(0))
  patch by: slugonamission at gmail dot com
 [2010-11-06 19:32 UTC]
-Status: Open +Status: Closed -Assigned To: +Assigned To: felipe
 [2010-11-06 19:32 UTC]
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
Thank you for the report, and for helping us make PHP better.

Thanks for the patch!
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Sat Aug 24 14:01:28 2019 UTC