|  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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: drew at dinomite dot net
New email:
PHP Version: OS:


 [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-2022 The PHP Group
All rights reserved.
Last updated: Wed Dec 07 21:04:14 2022 UTC