Re: bug in echo function?

From: Date: Sat, 19 Jan 2002 16:56:04 +0000
Subject: Re: bug in echo function?
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-81228@lists.php.net to get a copy of this message
"Billy Harvey" <Billy.Harvey@thrillseeker.net> wrote in message news:1011380849.646.398.camel@rhino.thrillseeker.net... > On Fri, 2002-01-18 at 13:54, Darren Gamble wrote: > > Good day, > > > > The reason that the first statement doesn't work as intended is due to the > > order that the operands are processed. > > > > The operands in the line: > > > > "<td>" . ($i*8)+$j . "</td>" > > > > are being processed like this: > > > > ("<td>" . ($i*8))+($j . "</td>") > > > > If you change the line to: > > > > "<td>" . (($i*8)+$j) . "</td>" > > > > then you'll get the desired result. > > > > Rule of thumb: Use parenthesis whenever you have a complex operation to > > ensure the result is what you want. > > Hmmm - so my assumption that the concatenation operator between the > strings gives them a delination equivalent to listing this as three > separate echo statements is incorrect, I take it. > > Shouldn't the echo function process it in this manner from a standpoint > of consistency? > > Thanks for the clarification. > > Billy > Rather than concatenating strings, you can use commas with echo as well: echo "<td>", ($i * 8) + $j, "</td>"; I *think* that you may in fact get a VERY SLIGHT increase in performance by doing it this way, because PHP will simply dump each 'piece' to the output buffer/to the browser one by one rather than having to go through the work of building one large string and then outputting that. Caveats: This won't work if you use the function-like syntax for echo << echo(foo, bar, baz) /* this won't work */ >>, but as your example code doesn't use it I'm imagining you probably aren't either. -- Daniel Grace <rubein@earthlink.net>

« previous php.general (#81228) next »