-2

Possible Duplicate:
Reference - What does this symbol mean in PHP?

I don't know if this has been asked before, but here goes: What's the difference between <?php, <?=, and <??
I'm just curious, and people have been telling me to use <?php instead of <?, but I just use <? because it works for me and it's faster. I ain't seein' no diff'rence (redneck accent for extra pleasures...).

Community
  • 1
  • 1
finst33
  • 141
  • 1
  • 3
  • 11

1 Answers1

2

<?php and <? are equivalent, except it's generally preferred to use <?php since not every server configuration may have the short opening PHP tags option enabled.

<?= is a shortcut for echoing back the value of a variable/expression, i. e.

<?=$var ?>

is similar to

<?php echo $var; ?>
  • The shorter version is also preferred when inserting small snippets of PHP into normal markup... That's just for readability I suppose... – Lix Dec 30 '12 at 22:53
  • 6
    Not preferred by me I tells ya! Those damn kids with their short open echo's nowadays :( Get off my lawn!! :) – PeeHaa Dec 30 '12 at 22:55
  • @pee - It's true.. I've been shouted at for wasting time refactoring every appearance of ``... – Lix Dec 30 '12 at 22:56
  • 3
    @PeeHaa Actually I *never* use the short version. I ceased to use it the day I read that it may break compatibility with some servers. –  Dec 30 '12 at 22:56
  • @PeeHaa :D But when you use PHP as the template engine it can make things easier to overview. However, like with many other things: Use it wisely (or not at all, if you prefer ;)). But I don't think they are bad at all. – KingCrunch Dec 30 '12 at 22:58
  • @H2CO3 The short-echo-syntax `=` is always enabled with 5.4. Nothing will break anymore :) – KingCrunch Dec 30 '12 at 22:58
  • 2
    @KingCrunch as soon as PHP 5.4 is reasonably spread, you will be right, but many hosting services don't even have 5.3 yet. – dualed Dec 30 '12 at 23:01
  • @KingCrunch Well, I'd rather not rely upon **web service providers!** having the most recent versions of PHP. They're lazy and they don't. :) –  Dec 30 '12 at 23:03
  • @dualed Oh, this argument again ... If your hoster still uses a not-maintained version, you should go and look for a new one! Maybe it's just me, but I wouldn't pay for a hoster, who doesn't care about his costumers. You are right with 5.4, but it will come ;) However, I prefer environments, where I have at least a little bit control about the setup. – KingCrunch Dec 30 '12 at 23:03
  • @KingCrunch Well, after all, I just go ahead and write my program in C if PHP gets on my nerves :D –  Dec 30 '12 at 23:04
  • @KingCrunch if you want to write software that you don't install yourself, you will have to ensure *somehow* that it works on most systems. Using the opening tag that you can not disable instead of the one you can - or even have to enable - is one of the things to do and it does not cost you much. – dualed Dec 30 '12 at 23:07
  • @dualed When I'm going to write such software, I don't use the short-tags too, but thats not the point. I would recommend to use a secure environment, because it doesn't make me happy to know, that someone may blame me for being hacked, because he used an insecure setup. It's not hard to find a new, more reliable hoster nowadays. 5.2 is old and unmaintained. I would not write _new_ software for it nowadays. – KingCrunch Dec 30 '12 at 23:11