php.net |  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
 [2010-08-29 19:42 UTC] drew at dinomite dot net
Description:
------------
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:
---------------
<?php
// Ensure we hit the backtrack limit
ini_set('pcre.backtrack_limit', 1);

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

echo 'Return value is ';
var_dump($ret);

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

Patches

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

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-11-06 19:32 UTC] felipe@php.net
Automatic comment from SVN on behalf of felipe
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=305132
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] felipe@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: felipe
 [2010-11-06 19:32 UTC] felipe@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.

Thanks for the patch!
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 08:01:29 2024 UTC