php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #43788 prep_replace returns null
Submitted: 2008-01-08 15:05 UTC Modified: 2008-01-08 16:07 UTC
From: david at dfoerster dot de Assigned:
Status: Not a bug Package: PCRE related
PHP Version: 5.2.5 OS: Linux
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.
Password:
Status:
Package:
Bug Type:
Summary:
From: david at dfoerster dot de
New email:
PHP Version: OS:

 

 [2008-01-08 15:05 UTC] david at dfoerster dot de
Description:
------------
The preg_replace function returns null when a certain string is passed as 
haystack. Removing some lines from the string fixes the issue. The search 
pattern is not even found in the problematic string.

This problem occurs with all PHP 5 versions I tested (5.2.0, 5.2.4, 5.2.5). It does 
not occur with PHP 4.

(The search pattern uses back-references in case that matters.)

Reproduce code:
---------------
Run this script: http://dfoerster.de/misc/preg_replace_bug

It prints the string length before and after the matching. With PHP 5 the length after the matching is 0, with PHP 4 it's the same as before as no replacement takes places.

Expected result:
----------------
strlen returns the same length as before the matching.

Actual result:
--------------
strlen returns 0 after matching.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-01-08 15:09 UTC] david at dfoerster dot de
Removing the lines between {* and *} surprisingly fixes the problem.
 [2008-01-08 16:07 UTC] felipe@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

preg_last_error() returns 2 (= PREG_BACKTRACK_LIMIT_ERROR).
I.e. backtrack limit was exhausted.

See http://pcre.org/man.txt for explanation about backtracking.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon May 27 20:01:32 2024 UTC