<? new opening tag?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
rkalexander
Forum Newbie
Posts: 10
Joined: Tue May 30, 2006 9:30 am

<? new opening tag?

Post by rkalexander »

I've seen people using just

Code: Select all

<?
instead of

Code: Select all

<?php
as an opening php tag. Is the new tag valid, and when did it happen?

Probably a noob question, but I want to know. Thanks :D
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

It's called a short tag, it's been around for quite some time, but is being phased out rather quickly. So don't use it.
rkalexander
Forum Newbie
Posts: 10
Joined: Tue May 30, 2006 9:30 am

Post by rkalexander »

Thank you Feyd.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Short tags are evil and are being depricated in PHP6. If you have them in any of your code, I would seriously recommend updating them to long tags as on some PHP5 systems this is off (in fact, I think PHP5 has them off by default). If short_tags is off and you try to use them you will have some rather interesting results (as I found out recently with a borroed piece of code I was working with).
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post by Ollie Saunders »

If you run your own version of PHP for development, turn off short-tags so that you will be forced to comply.
User avatar
Adesso
Forum Newbie
Posts: 9
Joined: Fri Jan 21, 2005 3:49 am
Location: Germany

Post by Adesso »

I have been using the

Code: Select all

<?php
for a while now, but still have to figure out how I can improve the short hand

Code: Select all

<?=$var?>
, as

Code: Select all

<?php=$var?>
does not work.

Sometimes using the <?= is usefull for printing out variable values, as I dont like using the long winded echo, but if the short hand is being depricated, what is a developer to do when trying to output variable values in a script?

Any suggestions ?
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

There isn't a shortcut with short tags disabled.

Code: Select all

<?=$var;?>
Would just have to become

Code: Select all

<?php echo $var; ?>
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

scottayy wrote:There isn't a shortcut with short tags disabled.

Code: Select all

<?=$var;?>
Would just have to become

Code: Select all

<?php echo $var; ?>
Which I think is cleaner anyway. At least it's consistent :) I don't find the word "print" or "echo" overly offensive or scary... most template languages look scarier than that :D
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

When I was a newbie, this

Code: Select all

<?php echo $var; ?>
made a lot more sense to me than

Code: Select all

<?=$var;?>
So I have been using it all along.
Post Reply