Glen Solsberry
Glen Solsberry

Reputation: 12320

Difference between <?php echo $session_id ?> and <?= $session_id ?>

Is there any particular reason to use one over the other? I personally tend to use the latter, as it just seems to flow better to me.

Upvotes: 6

Views: 1212

Answers (7)

rebellion
rebellion

Reputation: 6740

Just an addon question. I've read a few years ago that using <? and ?> is not recommended due to security issues. Is this correct?

Upvotes: 0

Nate Ferrero
Nate Ferrero

Reputation:

I would assume that <?php= $session_id; ?> works fine, and does not have the issue of portability.

Upvotes: 0

Mike B
Mike B

Reputation: 32155

Short tags are disabled on a significant amount of php installation so I never use

<?=$my_var?> // Bad Portability

<?php echo $my_var; ?> // Good Portability!

Upvotes: 0

ohnoes
ohnoes

Reputation: 5612

short_open_tag boolean

Tells whether the short form ( ) of PHP's open tag should be allowed. If you want to use PHP in combination with XML, you can disable this option in order to use inline. Otherwise, you can print it with PHP, for example: . Also if disabled, you must use the long form of the PHP open tag ( ).

Note: This directive also affects the shorthand

Source.

Upvotes: 1

PEZ
PEZ

Reputation: 17004

The shorthand is clearer. It says, with as few words possible:

"Here, an expressions is echoed and nothing else is going on."

Upvotes: 0

Rob Prouse
Rob Prouse

Reputation: 22647

As far as I know, they are functionally equivalent except the second can be disabled in configurations so isn't as portable.

Upvotes: 3

Brian Fisher
Brian Fisher

Reputation: 23989

They do the same thing, the <?= is just called the short tag and is shorthand for <?php echo. You have to make sure the short tags are enabled to use the <?= notation.

Upvotes: 13

Related Questions