Re: echo VS print : that's a cool behavior !
| From: | Andrew Ballard | Date: | Tue, 23 Oct 2007 15:54:03 +0000 |
| Subject: | Re: echo VS print : that's a cool behavior ! | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-263546@lists.php.net to get a copy of this message | ||
On 10/23/07, Robert Cummings <robert@interjinn.com> 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