|
Posted by Chung Leong on 11/10/06 16:53
R. Rajesh Jeba Anbiah wrote:
> Chung Leong wrote:
> <snip>
> > Text outside of <?php ?> is compiled to echo operations. So there's no
> > basic difference between the two methods.
>
> If it's true, manual is contradicting:
>
> <quote src="http://in.php.net/language.basic-syntax#AEN2651">
>
> <snip>
> } else {
> ?>
> <strong>This is false.</strong>
> <?php
> }
> ?>
>
> This works as expected, because when PHP hits the ?> closing tags, it
> simply starts outputting whatever it finds until it hits another
> opening tag. The example given here is contrived, of course, but for
> outputting large blocks of text, dropping out of PHP parsing mode is
> generally more efficient than sending all of the text through echo() or
> print().
>
> </quote>
It's poorly worded in the manual. Clearly, what is expected is that the
conditional would determine whether the HTML appear or not. If PHP
simply outputs anything outside of <?php ... ?>, then both blocks would
always appear. Nor would the following work as "expected."
<?php foreach($words as $word) { ?>
<li><?php echo $word; ?></li>
<?php } ?>
Think about it. The way I described it is the only way it could work.
The PHP language engine cannot control something that isn't part of the
code-stream.
Anyway, it's in the source code. If you look in zend_compile.c, you
will find this:
switch(retval) {
[...]
case T_OPEN_TAG_WITH_ECHO:
retval = T_ECHO;
break;
[...]
}
retval comes from lexical analyzer (lex). As you can see, when <?php is
encountered, an echo op-code is added--for the text that comes before.
Navigation:
[Reply to this message]
|