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

From: Date: Wed, 05 Nov 2008 12:16:20 +0000
Subject: #45440 [Bgs]: preg_replace does not do replacements inside $subject
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-1363@lists.php.net to get a copy of this message
ID: 45440 User updated by: aremo at ngi dot it Reported By: aremo at ngi dot it Status: Bogus Bug Type: Documentation problem Operating System: Linux PHP Version: Irrelevant New Comment: I guess "clearly" is in the eye of the beholder. I, for one, was certainly misled by the chosen phraseology. The manual does say that the new subject is returned, but still makes it sound as the replacements are made directly on $subject (e.g. "If subject is an array, then the search and replace is performed on every entry of subject"). Of course $subject is passed by value, so that can't be; but a well written *reference* manual does not leave stuff as an exercise to the reader. Previous Comments: ------------------------------------------------------------------------ [2008-11-05 10:46:20] vrana@php.net 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. ------------------------------------------------------------------------ [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 (#1363) next »