This is a patch to fix "Bug #52732 Docs say preg_match() returns FALSE on
error, but it returns int(0)" (http://bugs.php.net/bug.php?id=52732).

The documentation states that preg_match should return FALSE on error,
although it returns 0 if it breaks the recursion or backtrack limit. This
just checks the error code before returning the number of matches. This also
patches a couple of tests that relied on preg_match returning 0 on error.

~Jamie
Index: ext/pcre/php_pcre.c
===================================================================
--- ext/pcre/php_pcre.c (revision 304164)
+++ ext/pcre/php_pcre.c (working copy)
@@ -754,7 +754,13 @@
        efree(offsets);
        efree(subpat_names);
 
-       RETVAL_LONG(matched);
+       /* Did we encounter an error? */
+       if(PCRE_G(error_code) == PHP_PCRE_NO_ERROR) {
+               RETVAL_LONG(matched);
+       }
+       else {
+               RETVAL_FALSE;
+       }
 }
 /* }}} */
 
Index: ext/pcre/tests/bug52732.phpt
===================================================================
--- ext/pcre/tests/bug52732.phpt        (revision 0)
+++ ext/pcre/tests/bug52732.phpt        (revision 0)
@@ -0,0 +1,13 @@
+--TEST--
+Bug #52732 (Docs say preg_match() returns FALSE on error, but it returns 
int(0))
+--INI--
+pcre.backtrack_limit=1
+--FILE--
+<?php
+$ret = preg_match('/(?:\D+|<\d+>)*[!?]/', 'foobar foobar foobar');
+
+var_dump($ret);
+
+?>
+--EXPECT--
+bool(false)
\ No newline at end of file
Index: ext/pcre/tests/backtrack_limit.phpt
===================================================================
--- ext/pcre/tests/backtrack_limit.phpt (revision 304164)
+++ ext/pcre/tests/backtrack_limit.phpt (working copy)
@@ -19,7 +19,7 @@
 
 ?>
 --EXPECT--
-int(0)
+bool(false)
 bool(true)
 int(10)
 bool(true)
Index: ext/pcre/tests/invalid_utf8_offset.phpt
===================================================================
--- ext/pcre/tests/invalid_utf8_offset.phpt     (revision 304164)
+++ ext/pcre/tests/invalid_utf8_offset.phpt     (working copy)
@@ -22,7 +22,7 @@
 echo "Done\n";
 ?>
 --EXPECT--
-int(0)
+bool(false)
 array(0) {
 }
 bool(true)
Index: ext/pcre/tests/recursion_limit.phpt
===================================================================
--- ext/pcre/tests/recursion_limit.phpt (revision 304164)
+++ ext/pcre/tests/recursion_limit.phpt (working copy)
@@ -19,7 +19,7 @@
 
 ?>
 --EXPECT--
-int(0)
+bool(false)
 bool(true)
 int(1)
 bool(true)
-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to