#45440 [Opn->Bgs]: preg_replace does not do replacements inside $subject

From: Date: Wed, 05 Nov 2008 10:46:20 +0000
Subject: #45440 [Opn->Bgs]: preg_replace does not do replacements inside $subject
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-1355@lists.php.net to get a copy of this message
ID: 45440 Updated by: vrana@php.net Reported By: aremo at ngi dot it -Status: Open +Status: Bogus Bug Type: Documentation problem Operating System: Linux PHP Version: Irrelevant New Comment: preg_replace() clearly states that the replaced string is returned. Moreover, the $subject is not passed by reference so it can not be modified from inside the function. Previous Comments: ------------------------------------------------------------------------ [2008-07-06 15:22:19] aremo at ngi dot it Description: ------------ Probably a documentation bug. The manual page for preg_replace (especially in the description of $subject) makes it sound as though the replacements were made directly on $subject, while this is not the case. The replacements are only in the returned string. Reproduce code: --------------- #!/usr/bin/php <?php $subject = "big"; $result = preg_replace('#i#','u',$subject); echo $subject.' '.$result; ?> Expected result: ---------------- If the replacement took place in $subject, the program should output "bug bug". Actual result: -------------- The program outputs "big bug". ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=45440&edit=1

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