[PHP] echo VS print : that's a cool behavior !
Hello everyone. We all know the difference between print and echo, but has someone ever tried to combine them together ?? Right, try this : ?php echo coucou . print('v ' . print('u ' . print('toctoc ') . 'hihi ') ) . 'tata ' . print('zozo ' . print('pupu ')); And guess the result ... Can someone explain it ? ( the result is : toctoc hihi u 1pupu zozo 1v 1tata 1coucou 1 )
Re: [PHP] echo VS print : that's a cool behavior !
On Tue, 2007-10-23 at 17:34 +0200, Julien Pauli wrote: ?php echo coucou . print('v ' . print('u ' . print('toctoc ') . 'hihi ') ) . 'tata ' . print('zozo ' . print('pupu ')); That's not cool, that's a mess. Why doe sit happen the way it does? First off, print() is a function so nesting functions means the innermost functions get processed first, this is why the output has mangled order. The 1's show up in the output because you're concatenating the return value of the print() function which is true for success. Cheers, Rob. -- ... SwarmBuy.com - http://www.swarmbuy.com Leveraging the buying power of the masses! ... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] echo VS print : that's a cool behavior !
On 10/23/07, Robert Cummings [EMAIL PROTECTED] wrote: On Tue, 2007-10-23 at 17:34 +0200, Julien Pauli wrote: ?php echo coucou . print('v ' . print('u ' . print('toctoc ') . 'hihi ') ) . 'tata ' . print('zozo ' . print('pupu ')); That's not cool, that's a mess. Why doe sit happen the way it does? First off, print() is a function so nesting functions means the innermost functions get processed first, this is why the output has mangled order. The 1's show up in the output because you're concatenating the return value of the print() function which is true for success. Agreed it's a mess, and I don't know why anyone would do it, but that's only part of the story. I don't think the OP was wondering where the 1s came from; at least I'm not. I am wondering why it displays: toctoc hihi u 1pupu zozo 1v 1tata 1coucou 1 instead of toctoc u 1hihi v 1pupu zozo 1coucou 1tata 1 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] echo VS print : that's a cool behavior !
At 11:46 AM -0400 10/23/07, Robert Cummings wrote: On Tue, 2007-10-23 at 17:34 +0200, Julien Pauli wrote: ?php echo coucou . print('v ' . print('u ' . print('toctoc ') . 'hihi ') ) . 'tata ' . print('zozo ' . print('pupu ')); That's not cool, that's a mess. Why doe sit happen the way it does? First off, print() is a function so nesting functions means the innermost functions get processed first, this is why the output has mangled order. The 1's show up in the output because you're concatenating the return value of the print() function which is true for success. Cheers, Rob. -- Rob: Good call on the 1 return. Maybe this will help: http://www.webbytedd.com/bbb/echo-print/ Cheers, tedd -- --- http://sperling.com http://ancientstones.com http://earthstones.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] echo VS print : that's a cool behavior !
Hello everyone. We all know the difference between print and echo, but has someone ever tried to combine them together ?? Right, try this : ?php echo coucou . print('v ' . print('u ' . print('toctoc ') . 'hihi ') ) . 'tata ' . print('zozo ' . print('pupu ')); And guess the result ... Can someone explain it ? ( the result is : toctoc hihi u 1pupu zozo 1v 1tata 1coucou 1 ) Precedence. _ Windows Live Hotmail and Microsoft Office Outlook – together at last. Get it now. http://office.microsoft.com/en-us/outlook/HA102225181033.aspx?pid=CL100626971033
Re: [PHP] echo VS print : that's a cool behavior !
On Tue, 2007-10-23 at 11:54 -0400, Andrew Ballard wrote: On 10/23/07, Robert Cummings [EMAIL PROTECTED] wrote: On Tue, 2007-10-23 at 17:34 +0200, Julien Pauli wrote: ?php echo coucou . print('v ' . print('u ' . print('toctoc ') . 'hihi ') ) . 'tata ' . print('zozo ' . print('pupu ')); That's not cool, that's a mess. Why doe sit happen the way it does? First off, print() is a function so nesting functions means the innermost functions get processed first, this is why the output has mangled order. The 1's show up in the output because you're concatenating the return value of the print() function which is true for success. Agreed it's a mess, and I don't know why anyone would do it, but that's only part of the story. I don't think the OP was wondering where the 1s came from; at least I'm not. I am wondering why it displays: toctoc hihi u 1pupu zozo 1v 1tata 1coucou 1 instead of toctoc u 1hihi v 1pupu zozo 1coucou 1tata 1 My bad, print is not a function, and so: print( 'toctoc ' ).'hihi '; is equivalent to: print( 'tocktoc '.'hihi ' ); Parenthesis are option and only server to control precedence. But unlike echo print does return a value. Cheers, Rob. -- ... SwarmBuy.com - http://www.swarmbuy.com Leveraging the buying power of the masses! ... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] echo VS print : that's a cool behavior !
On 10/23/07, Robert Cummings [EMAIL PROTECTED] wrote: My bad, print is not a function, and so: print( 'toctoc ' ).'hihi '; is equivalent to: print( 'tocktoc '.'hihi ' ); Ah. I see. I knew they were optional, but I didn't know that when you include them PHP evaluates ('toctoc') before it passes the value off to print(). I just figured that with or without the parentheses it would pass 'toctoc' to print() and return a result that would be concatenated inline with the other values. I guess that's the part I didn't understand about the difference between a function and a language construct in PHP. As for the OP, I still don't know why anyone would even dream of creating code that does this other than to see what would happen if we :-) Andrew -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] echo VS print : that's a cool behavior !
That's just the case : too see what happens if I agree that anyone will never meet such a case in everydays' programming. ;-) 2007/10/23, Andrew Ballard [EMAIL PROTECTED]: On 10/23/07, Robert Cummings [EMAIL PROTECTED] wrote: My bad, print is not a function, and so: print( 'toctoc ' ).'hihi '; is equivalent to: print( 'tocktoc '.'hihi ' ); Ah. I see. I knew they were optional, but I didn't know that when you include them PHP evaluates ('toctoc') before it passes the value off to print(). I just figured that with or without the parentheses it would pass 'toctoc' to print() and return a result that would be concatenated inline with the other values. I guess that's the part I didn't understand about the difference between a function and a language construct in PHP. As for the OP, I still don't know why anyone would even dream of creating code that does this other than to see what would happen if we :-) Andrew -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php