php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Return to Bug #52732
Patch preg_match_false_on_error revision 2010-10-07 13:39 UTC by slugonamission at gmail dot com
Patch Bug_52732_preg_match_false_on_error revision 2010-10-07 13:37 UTC by slugonamission at gmail dot com

Patch preg_match_false_on_error for PCRE related Bug #52732

Patch version 2010-10-07 13:39 UTC

Return to Bug #52732 | Download this patch
This patch renders other patches obsolete

Obsolete patches:

Patch Revisions:

Developer: slugonamission@gmail.com

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 Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Nov 23 08:01:28 2024 UTC