OOOOHHHHHH! Now that makes perfect sense. 
Thank you Rasmus for that indepth reply and also the , vs . "trick"

> -----Original Message-----
> From: Rasmus Lerdorf [mailto:[EMAIL PROTECTED] 
> Sent: Friday, April 04, 2003 10:11 PM
> To: Daevid Vincent
> Cc: [EMAIL PROTECTED]
> Subject: RE: [PHP] Re: Found a bug in 4.2.3 re: <TD> and echo 
> vs. <?php?>
> 
> 
> You are getting completely mixed up.  Simplifying your example:
> 
>         function foo() { echo "foo"; }
> 
>         $a = "<TD>".foo()."</TD>";
> 
> Will you agree that this is bogus code?  foo() is not going to return
> anything, so the resulting value of $a is going to be "<TD></TD>".
> Correct?  But while that assignment is happening the foo() 
> function echoes
> something, so you will see "foo" in the output, but it has 
> nothing to do
> with what ends up in $a.  Nothing changes when you change the 
> code to be:
> 
>         function foo() { echo "foo"; }
> 
>         echo "<TD>".foo()."</TD>";
> 
> The parser is going to build a string to be echoed since you used the
> string concatenation operator (dot).  While building that 
> string one of
> the components happen to output something, so that something will get
> output.  Then the string that was built will be output.  So 
> what you see
> is:
> 
>         foo<TD></TD>
> 
> Perhaps it is clearer if we make the function return something:
> 
>         function foo() { echo "foo"; return "bar"; }
> 
>         echo "<TD>".foo()."</TD>";
> 
> What do you think the output will be here?  We build a string 
> out of the
> components, but while building, foo() happens to echo "foo", then we
> finish constructing the string and output the final string.  
> So the result
> is:
> 
>        foo<TD>bar</TD>
> 
> As someone else pointed out, if you use commas here, things 
> change a bit:
> 
>         function foo() { echo "foo"; }
> 
>         echo "<TD>",foo(),"</TD>";
> 
> The comma syntax for echo is basically a shortcut for executing echo
> multiple times.  The above is equivalent to writing:
> 
>         echo "<TD>";
>         echo foo();
>         echo "</TD>";
> 
> In this case things will be output in the correct order as we are no
> concatenating a bunch of parts to make a single string before 
> echoing it
> in this case.
> 
> -Rasmus
> 
> On Fri, 4 Apr 2003, Daevid Vincent wrote:
> 
> > Mmm. I'm still not following and not completely convinced.
> >
> > Changing "echo alarmLightYMD();" to simply 
> "alarmLightYMD();" in the bottom
> > function doesn't print anything in the table cell at all 
> (for the first test
> > case).
> >
> > While your idea at first makes sense and does seem like a 
> newbie mistake
> > (and you are correct, I do have nested "echo" statements 
> come to think of
> > it). What I don't get is why it's not consistent. 
> "Expanding" the relevant
> > lines, it should be like this:
> >
> > echo "<TD>".(echo "<IMG SRC='images/light_red.gif'>")."</TD>";
> >
> > Which fails, and the other line would be (which works):
> >
> > <TD><?php echo (echo "<IMG SRC='images/light_red.gif'>"); ?></TD>
> >
> > In my book, they're both double echoing the output if you 
> will... Are you
> > with me on that?
> >
> > So again, why does the second one work and the first one doesn't?
> >
> > > -----Original Message-----
> > > From: Philip Hallstrom [mailto:[EMAIL PROTECTED]
> > > Sent: Friday, April 04, 2003 5:20 PM
> > > To: Daevid Vincent
> > > Cc: [EMAIL PROTECTED]
> > > Subject: [PHP] Re: Found a bug in 4.2.3 re: <TD> and echo 
> vs. <?php?>
> > >
> > >
> > > It's a coding error... at least I think so.
> > >
> > > change alarmLightMySQL just return the results not "echo"
> > > them... echoing
> > > them doesn't make much sense inside another echo statement...
> > >
> > > On Fri, 4 Apr 2003, Daevid Vincent wrote:
> > >
> > > > Here, try this bullshit...
> > > >
> > > > I can't upgrade to a more recent version as I'm not in
> > > control of the
> > > > server, but I've tried it with both 4.1.2 and 4.2.3 on
> > > linux with a RH
> > > > install. Can anyone confirm or dispute this bug exists in
> > > later versions?
> > > >
> > > > How does a parsing error like this go un-noticed for so long?
> > > >
> > > > Obviously I took out all the interesting stuff in the page
> > > and so that can't
> > > > be blamed. This is about as bare skeleton test case as 
> you can get.
> > > >
> > > > *sigh*
> > > >
> > > > ------------snip----------------
> > > >
> > > > <?php
> > > >         function alarmLightYMD()
> > > >         {
> > > >                 return "<IMG SRC='images/light_red.gif'>";
> > > >         }
> > > >
> > > >         function alarmLightMySQL()
> > > >         {
> > > >                 echo alarmLightYMD();
> > > >         }
> > > > ?>
> > > > <html>
> > > > <head>
> > > >         <title>FUCKED UP PHP Bug #1234170238741023</title>
> > > > </head>
> > > >
> > > > <body>
> > > > PHP Version 4.1.2<BR>
> > > > PHP Version 4.2.3<BR>
> > > > <BR>
> > > > Why the FUCK doesn't this work!!!!
> > > > <P>
> > > > <TABLE BORDER="1">
> > > > <?php
> > > > for ($i = 0; $i < 10; $i++ ) {
> > > >          echo "<TR>";
> > > >                 echo "<TD>".alarmLightMySQL()."</TD>";
> > > >                 echo "<TD>this fails!</TD>";
> > > >          echo "</TR>";
> > > > }
> > > > ?>
> > > > </TABLE>
> > > >
> > > > <HR>
> > > >
> > > > YET THIS DOES!
> > > > <P>
> > > > <TABLE BORDER="1">
> > > > <?php for ($i = 0; $i < 10; $i++ ) { ?>
> > > >          <TR>
> > > >                 <TD><?php echo alarmLightMySQL(); ?></TD>
> > > >                 <TD>this works</TD>
> > > >          </TR>
> > > > <?php } ?>
> > > > </TABLE>
> > > > </body>
> > > > </html>
> > > >
> > > > ------------snip----------------
> > > >
> > > >
> > > >
> > > > "Ezekiel 25:17. The path of the righteous man is beset on
> > > all sides by the
> > > > inequities of the selfish and the tyranny of evil men.
> > > Blessed is he who in
> > > > the name of charity and goodwill shepherds the weak through
> > > the valley of
> > > > darkness, for he is TRULY his brother's keeper and the
> > > finder of lost
> > > > children. And I will strike down upon thee with GREAT 
> vengeance and
> > > > FU-U-U-URIOUS anger, those who attempt to poison, and
> > > destroy my brothers!
> > > > And you will KNOW my name is the Lord, when I lay my
> > > vengeance upon thee!"
> > > >
> > > >
> > > > --
> > > > PHP General Mailing List (http://www.php.net/)
> > > > To unsubscribe, visit: http://www.php.net/unsub.php
> > > >
> > > >
> > >
> > > --
> > > PHP General Mailing List (http://www.php.net/)
> > > To unsubscribe, visit: http://www.php.net/unsub.php
> > >
> >
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
> >
> 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to