Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Matthew Carter Newsgroups: comp.lang.php Subject: Re: Purpose for a str_replace with an embedded print_r return Date: Wed, 05 Nov 2014 15:50:39 -0500 Organization: Ahungry (http://ahungry.com) Lines: 68 Message-ID: <87a945z80w.fsf@ahungry.com> References: <064143e2-28d1-40e4-a76e-c6d28b05dddb@googlegroups.com> <2023723.LoZblivUAB@PointedEars.de> <45658857.s58lGopVbh@PointedEars.de> <1780873.BENQMAGEWm@PointedEars.de> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: mx02.eternal-september.org; posting-host="7c986cd4736462de309a749b207746fe"; logging-data="15993"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18NaZmgbZ0c5ED/iT5CSJyJ" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux) Cancel-Lock: sha1:Xp25YiJUpm8Li2hxvYzr0mdvAwU= sha1:GJHwANeISvkK5CjW2dLYoBEJRuA= Xref: csiph.com comp.lang.php:14475 Jerry Stuckle writes: > On 11/5/2014 9:32 AM, the pedantic troll Thomas 'Pointed Head' Lahn wrote: >> Jerry Stuckle wrote: >> >>> [abuse] Thomas 'Pointed Head' Lahn wrote: >>>> Jerry Stuckle wrote: >>>>> On 11/4/2014 12:58 PM, Christoph M. Becker wrote: >>>>>> Thomas 'PointedEars' Lahn wrote: >>>>>>> I think the proper idiom is “to kill two birds with one stone”. This >>>>>>> appears to be debug code, and if you pass “true” as second parameter >>>>>>> to print_r(), it returns the output instead of printing it. >>>>>> >>>>>> Good catch! At least a plausible explanation for the strange construct. >>>>>> […] >>>>> No, the OP already indicated the value was a simple string, not an array >>>>> or object reference, so the print_r() is unnecessary (and potentially >>>>> confusing). >>>> Which part of “debug code” did you not understand? >>> >>> Which part of "unnecessary code" did you not understand? >> >> It is unnecessary only *in your humble opinion*. However, in *debug* code >> one wants to have a contingency plan. One does not want to get the string >> representation of a non-string value when you can inspect the unusual array >> or object instead. >> >>> [abuse] >> >> Just go away. >> >> > > This is why you're so stoopid. The variable being debugged is a STRING > - as the OP said. It's not an array. It's not an object. It's a > STRING. But you don't understand the difference. > > Yes, please go away. Pedantic trolls like you are not welcome here. > > And on the way out, don't let the door hit you in the butt. You might > get a brain concussion. I did a quick test and there is a difference between using a plain string and a string wrapped in print_r when you store a an invalid character in the string and run the script via mod_php. Try the following snippet: You will notice that the character is not sent to the browser when passed through print_r (it is via the CLI though, so not sure if this is a mod_php feature). Changing the encoding to ISO will pass it in both cases (as it is a valid character in that set). -- Matthew Carter (m@ahungry.com) http://ahungry.com