php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #54954 preg_match() returns zero if an error occurred
Submitted: 2011-05-30 19:34 UTC Modified: 2011-06-30 08:02 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: benoit dot chenu at gmail dot com Assigned:
Status: Closed Package: PCRE related
PHP Version: 5.3.3 OS:
Private report: No CVE-ID: None
 [2011-05-30 19:34 UTC] benoit dot chenu at gmail dot com
Description:
------------
---
From manual page: http://www.php.net/manual/en/function.preg-match.php#Return Values
---

A bug was already opened (#51741) about this but not treated. If an error occurs (like reaching pcre.backtrack_limit), preg_match doesn't return FALSE as described in the documentation but returns 0.

It should be nice to update the documentation.


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-06-14 16:36 UTC] aharvey@php.net
-Status: Open +Status: Feedback
 [2011-06-14 16:36 UTC] aharvey@php.net
What version of PHP are you getting integer 0 back from preg_match() when the backtrack limit is hit? Everything I have to hand is returning boolean false, which is what I'd expect.
 [2011-06-30 08:02 UTC] benoit dot chenu at gmail dot com
-Status: Feedback +Status: Closed -Package: Documentation problem +Package: PCRE related -PHP Version: 5.3.6 +PHP Version: 5.3.3
 [2011-06-30 08:02 UTC] benoit dot chenu at gmail dot com
Hi,

I was testing on 5.3.3 (and not 5.3.6). I made a mistake when reporting. I change the version to 5.3.3 in bug's description.

I've just tested on latest version (5.3.6) and the problem is resolved. So this is not a documentation problem but a bug. I also change the package and bug type in description.

I finally found the bug report which was resolve the problem :

https://bugs.php.net/bug.php?id=52732

The bug fix was published with PHP 5.3.4


Just for information, the tests I was doing :

<?php
$buf = str_repeat('a', 100000).'b';
var_dump(preg_match('/^(.*?)b$/s', $buf));
var_dump(preg_last_error());


Result on PHP 5.3.3 :
int(0)
int(2)

Result on PHP 5.3.6 :
bool(false)
int(2)

I close the bug.
Thanks for your attention.
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Fri Oct 30 08:01:25 2020 UTC