Doc #51864 [NEW]: preg_replace returns NULL on error

From: Date: Wed, 19 May 2010 22:45:23 +0000
Subject: Doc #51864 [NEW]: preg_replace returns NULL on error
Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-4407@lists.php.net to get a copy of this message
From: Operating system: NA PHP version: Irrelevant Package: Regexps related Bug Type: Documentation Problem Bug description:preg_replace returns NULL on error Description: ------------ Sometimes preg_replace([Array],[Array],$subject) returns null, but the error cannot be reproduced using preg_replace($problem_regex,$repl,$subject). My attempt to reproduce it showed that $problem_regex was not a problem - the replacement worked as designed. I actually removed it from the arrays and did it separately under the assumption that the regex engine might have been biting off more than it could chew. If I shortened $repl, I was able to get the array version to work, but since my $repl was longer, I moved it to a separate call. The docs for preg_replace do not mention preg_last_error. That should be mentioned right where it says it returns NULL on error. Test script: --------------- // You may need to create several more patterns and replacements to get an error // Just make sure they're all legitimate $contents = file_get_contents("textfile.txt"); $find = array('<td><'.'?php readfile("/var/www/www.domain1.com/html/templates/leftmenu2_lfl.txt"); ?'.'></td><td width="663"', '#(?:<table .{450,500})?<\?php\s+readfile[^<>]*?templates/footer(?:lamps)?.txt[\'";) ]*\s*\?'.'>.*#s'); $replace = array('<td>file_get_contents('whatever').'</td><td width="601"', file_get_contents('newFooter.txt')); echo preg_replace($find, $replace, $contents); Expected result: ---------------- When the arrays are large enough and/or the patterns are complicated enough, The output will be empty. The "bug" is that there's no documentation on how to find out why it's empty. Is there a way? -- Edit bug report at http://bugs.php.net/bug.php?id=51864&edit=1 -- Try a snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=51864&r=trysnapshot52 Try a snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=51864&r=trysnapshot53 Try a snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=51864&r=trysnapshot60 Fixed in SVN: http://bugs.php.net/fix.php?id=51864&r=fixed Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=51864&r=needdocs Fixed in release: http://bugs.php.net/fix.php?id=51864&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=51864&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=51864&r=needscript Try newer version: http://bugs.php.net/fix.php?id=51864&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=51864&r=support Expected behavior: http://bugs.php.net/fix.php?id=51864&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=51864&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=51864&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=51864&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=51864&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=51864&r=dst IIS Stability: http://bugs.php.net/fix.php?id=51864&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=51864&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=51864&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=51864&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=51864&r=mysqlcfg

« previous php.doc.bugs (#4407) next »