tags:

views:

262

answers:

5

Sorry for the silly question, but I ran across code that used:

<?=$MAP_OBJECT->printOnLoad();?>
<?=$MAP_OBJECT->printMap();?>
<?=$MAP_OBJECT->printSidebar();?>

Is there anything special about <?= over <?php or just plain <? ?

+7  A: 

It's a shorthand for <?php echo $MAP_OBJECT->printOnLoad(); ?>. Simpler way to write it when you're making PHP-based templates and things.

Be careful, though. My understanding (though I've never run into it myself) is that the shorthand version can be disabled on some servers.

derekerdmann
Aye. They call it a short_open_tag. Details here, http://php.net/manual/en/ini.core.php.
Inkspeak
It's not only off on some servers -- it's off by default. So it's probably off on most servers.
Frank Farmer
@Frank Farmer: to prevent annoying tickets the public hostings turn short tags on, as well as globals :-S
zerkms
+1  A: 

<?= is not one thing. It's actually <? and then = . As @derekerdmann has mentioned, this is an unrecommended configuration.

Give the following a look:

Babiker
who said it's unrecommended?
Col. Shrapnel
+13  A: 

They are shorthand of <?php echo .... ?> known as short tags. You should avoid using them because:

  • They seem to be turned off on some servers
  • They can get you in trouble in terms of security
  • They can create conflict with processing instructions like <?xml ... ?>

Therefore you should never use them again, also have a look at:

PHP Short Open Tag: Convenient Shortcut or Short Changing Security?

Sarfraz
The `short_open_tag` ini option is **not** deprecated.
salathe
@salathe: See this with respect to your comment: http://stackoverflow.com/questions/3008614/should-short-tags-be-avoided-as-much-as-possible/3008626#3008626
Sarfraz
who is this Dorward guy? is he PHP core team member? Same for the Priebsch one. They are nobody. you cannot use it as a proof.
Col. Shrapnel
@Col. Shrapnel: I would *naturally end this with you* by saying you should provide your comments there as well so that things get cleared up for me as well as him. Also I don't know like Dorwand how expert you are at PHP so your argument cancels your comments for me too.
Sarfraz
No, you are wrong. one who states any statement, ought to bring positive proof. You just have no proof beside empty blab of some ignorant persons. And not a single official word from PHP team. My proof is just absence of such a word. That's logic. Simple enough even for you
Col. Shrapnel
@Sarfraz Ahmed: Col. Shrapnel is right. You have to proof your statements. Because without a proof they are just assumptions.
Gumbo
@Col. Shrapnel, @Gumbo: I already provided a proof in my answer. You must have seen the slide number 47 at : http://www.slideshare.net/thinkphp/php-53-and-php-6-a-look-ahead
Sarfraz
I have already asked you: who is that Priebsch guy? Does he any right to speak for the PHP core team? The answer is **no**.
Col. Shrapnel
@Gumbo: Is he still right from his last comment?
Sarfraz
@Gumbo: I have also updated my answer, you see i don't involve myself in arguments with that guy for obvious reasons but because you favored him, i need to respond to you only not him and never him in fact.
Sarfraz
From your link: "Conclusions: 1. We kill "<%" **but keep "<?"** . Correct your answer please.
Col. Shrapnel
There is a long discussion about the possible deprecation of short tags here: http://www.mail-archive.com/[email protected]/msg41839.html
nico
@Col. Shrapnel: You missed third point right? It says **We will not add "<?php =".** something asked by the OP. I think you are confusing between `<?` and `<?php=`.
Sarfraz
@Sarfraz Ahmed: The slides are not a proof in my opinion. The author of that slides, “Ajax ajax”, is not an authority I trust. You should only cite sources that are trustworthy concerning information about PHP’s future development.
Gumbo
@Sarfraz Ahmed: The report says they will remove `<%` (ASP style), they will keep `<?` (short tags) and they will not add `<?php =` (PHP tags with implicit `echo`).
Gumbo
@Gumbo: I again updated my answer and said in my comment to see the updated answer please, I believe confusion here created is between `<?` and `<?php=`. The OP has as can be seen the asked about later.
Sarfraz
@Sarfraz Ahmed: `<?php=` is currently not supported and won’t be supported in future versions (see the report you linked to). Only `<?=` is supported when allowing short open tags.
Gumbo
@Sarfraz Ahmed: Now I'm confused, seeing as YOU were the one who changed the question title and body from `<?=` to `<?php=`, why have you done that? The OP asked about `<?=`!
TooManyCooks
@TooManyCooks: Because that's what i believe he meant and also because of confustion betweeen `<?=` and `<?php=` . And we can conclude this discussion only when OP responds, If it is not what he is looking for, I will definitely either keep my answer or delete it :)
Sarfraz
@Sarfraz Ahmed: How about quoting this: “Which is one of the reasons we decided not to remove them in PHP 6.” – Rasmus Lerdorf, http://www.mail-archive.com/[email protected]/msg41853.html
Gumbo
+1  A: 

Just to correct all these misguiding answers:

short open tags are not going to be removed or deprecated.

Col. Shrapnel
+3  A: 

Rather than talking about whether short_open_tags is deprecated or not we should talk about the advantages and disadvantages when using short open tags:

Advantages

Using the short open tags <? along with <?= is shorter and probably easier to write than the standard opening tags <?php and <?php echo respectively. That’s quite handy when using PHP directly in a template. (That’s probably also the reason why PHP has an alternative syntax for control structures.)

Disadvantages

Requires a specific configuration

When using short open tags you are required to have short_open_tags enabled. If you or your web hosting provider decides to disable short_open_tags, your application probably won’t work any more and you can have some serious security issues. Because if short_open_tags is disabled, only the standard opening tags <?php are recognized and everything inside short opening tags is treated as plain text. (See also the blog post referenced in Sarfraz Ahmed’s answer.)

This requirement makes your PHP application less portable if you aim to write applications that are not just for you. That’a also why many recommend not to use short open tags (including the PHP manual):

Note: Using short tags should be avoided when developing applications or libraries that are meant for redistribution, or deployment on PHP servers which are not under your control, because short tags may not be supported on the target server. For portable, redistributable code, be sure not to use short tags.

Conflicts with XML processing instructions

Another issue is when using XML processing instructions like <?xml … ?>. When short_open_tags is enabled you cannot use them directly in your code but need to use PHP to output it:

If you want to use PHP in combination with XML, you can disable this option in order to use <?xml ?> inline. Otherwise, you can print it with PHP, for example: <?php echo '<?xml version="1.0"?>'; ?>.

Otherwise PHP will choke on the xml in <?xml.

Now some last words about the deprecation: Currently short_open_tags is not deprecated. Otherwise the manual would state that explicitly. Additionally, Rasmus Lerdorf, inventor of PHP, wrote in a reply on the question “Is it true that short_open_tag is deprecated in PHP 6?” on the internals mailing list that there were several reasons not to remove short_open_tags in PHP 6:

Which is one of the reasons we decided not to remove them in PHP 6.

Gumbo