Re: Newbie question about <?= ?>

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




----- Original Message ----- From: "Mike Borrelli" <mike@xxxxxxxxxx>
To: "Ray Hauge" <ray.hauge@xxxxxxxxxxxxxxxxxxxxxxx>
Cc: <php-general@xxxxxxxxxxxxx>; "Mike Borrelli" <mike@xxxxxxxxxx>
Sent: Sunday, September 10, 2006 6:52 AM
Subject: Re:  Newbie question about <?= ?>


Okay, after thinking about it, and looking at the replies, it seems as
though there is only one situation where the short tags break things, and
that's in XML with the <? ?> pair being valid for XML.


As I said <? ?> is not valid XML, it misses the code to identify the processor to deal with the contents. XML expects what it calls a PITarget (PI being Processing Instruction, which is what this <?PITarget ?> pair is) right after the first question mark.

Yes, enabling the short tags is in the ini file, but is it on by default
and require effort to change?

That's the real question, I think.  Not, why shouldn't I use them the way
they are, but why is it that the <?= ?> tag isn't designed into the
language to be acceptable?

Which language? If it only was for PHP, anything could be designed into it, but it does not have the environment all to itself and it might have to coexist with other standards. XML requires the PITarget, and that's it. Nevertheless, you are not required to be XML compatible in your setup and indeed, in most cases, this is irrelevant.

Honestly, the <? ?> pair just feels a little lazy, since all you save are
the 4 characters "php ", and all the code inside is the same.  The <?= ?>
tag gives you 7 characters free and does something unique.

The situation I think of using it the most in is something such as:
 <li><a href="<?= $post->permLink; ?>">...</a></li>

Which looks cleaner, in my opinion, than:
 <li><a href="<?php print $post->permLink; ?>">...</a></li>

Not a whole lot larger, no, and perhaps you might say, Well, the second
way is more explicit!  Yes.

Also, shouldn't it be possible to check for <?= ?> and, based on the '='
there, pop out of the parser if it comes across <?xml...?> ?


xml is not the only valid PITarget out there, thus, you cannot parse everything but xml since the list of 'buts' is endless. Anyway, if you care for XML compatibility , it is important that the <?xml PI is in clear text at the beginning and that you don't use short tags, otherwise if you do not care for compatibility, then the <?xml can be echoed from within php as a normal string, which is a good thing since, after all, the <?xml in clear text at the beginning is announcing that the whole document is xml compatible which, with short tags enabled, it is not. The output of that script, which would include the echoed <?xml, would be XML compatible.

I personally don't care much for XML compatibility in my PHP scripts, I care that the output of those scripts is XML compatible, if it has to. I still think the recomendation is valid though I am still to see any place which would deny itself the chance to run zillions of packages out there to achieve some theoretical compatibility at a point (PHP source code) where it is irrelevant.

Satyam


Cheers,
Mike

As was said before, the major reasons for not using short tags are:

1) Not everyone has access to the ini file, and might not be able to use
short
tags. If you're releasing your code to the public, you want to work in as
many places as possible, so then you should use <?php instead.

2) when using XML files, they use <?xml, and the <? is recognized as the
start
of a PHP block, but the following syntax will be correct and your code
will
fail.  I have seen that someone suggested having PHP recognize <?xml as
not
being a PHP short tag, but I don't remember where off the top of my head.

This does bring up an interesting idea though.  It appears that <?php= is
not
valid.  A lot of people use <?= as a sort of templating system instead of
adding the complexity of smarty or other templating systems (which are
fine).
Is it possible, or will it be possible, to use <?php="blah" ?>

--
Ray Hauge
Programmer/Systems Administrator
American Student Loan Services
www.americanstudentloan.com
1.800.575.1099


--
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


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux