<?=$variable?>

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
User avatar
fluvly
Forum Newbie
Posts: 10
Joined: Wed Sep 23, 2009 10:08 am

<?=$variable?>

Post by fluvly »

I found this syntax in a code:

Code: Select all

<?=$variable?>


They seem like the php start and end tags, but what does the "equal" sign do? I tried replacing it with:

Code: Select all

<?php $variable ?>


It didn't work. Thanks to anyone who can help me.
watson516
Forum Contributor
Posts: 198
Joined: Mon Mar 20, 2006 9:19 pm
Location: Hamilton, Ontario

Re: <?=$variable?>

Post by watson516 »

<?=$variable?> is a short form of <?php echo $variable; ?>

Don't use it.
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: <?=$variable?>

Post by jackpf »

watson516 wrote:Don't use it.
Why not?
User avatar
Mirge
Forum Contributor
Posts: 298
Joined: Thu Sep 03, 2009 11:39 pm

Re: <?=$variable?>

Post by Mirge »

watson516 wrote:<?=$variable?> is a short form of <?php echo $variable; ?>

Don't use it.
That begs for the next question, "why not?"

It can cause confusion with XML, and some people don't have access to PHP configuration to enable short tags. See: http://stackoverflow.com/questions/2006 ... ble-to-use

Now, from my own personal experience... I've yet to run into a problem using short tags. Every client I've ever had either had short tags enabled, or had access to configuration to enable it. Keep in mind, the software I write for my clients is designed to run on THEIR server(s) only. It's not distributed software.

For software that will be distributed (ie: sold), I would recommend using the full version (ie: <?php echo $foo; ?>) over short tags purely for compatibility. If you are re-selling software that uses short tags, expect emails asking why things aren't working...


EDIT:
jackpf wrote:
watson516 wrote:Don't use it.
Why not?
Told ya! 8O
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: <?=$variable?>

Post by jackpf »

;)

Exactly. If it's running on your own server where you have access to its settings, then there's no reason not to use short tags. I find them extremely useful for templates. Saves a lot of repetitive typing.

Everyone says not to use them simply because they've been told not to. It doesn't necessarily make them bad though...
Post Reply