tags:

views:

91

answers:

3

whats the meaning of this line

<input type=text name="name" value="<?= $name ?>

if we are to declare as PHP shouldn't we write <?php instead of <?=

Thanks

+7  A: 

<?= ... ?> is shorthand for <?php echo ... ?>

Fragsworth
+3  A: 

using short tags is generally frowned upon nowadays but it's still an option in the php.ini. It's fine, it's just poor coding style and has some repercussions if you use multiple dynamic languages.

Chuck Vose
Not to mention short tags are deprecated as of php6
Matt
Considering PHP 6 is far from finished (it's not even in alpha stage yet), things can change -- even if it probably will not for this specific point.
Pascal MARTIN
PHP6? who? what? where? when?
gahooa
+9  A: 

<?= are PHP short open tags, which can be enabled (or disabled) via the open_short_tag directive in php.ini (quoting) :

This directive also affects the shorthand <?= , which is identical to <? echo . Use of this shortcut requires short_open_tag to be on.

And :

Also if disabled, you must use the long form of the PHP open tag (<?php ?> ).


This means your portion of code :

<input type=text name="name" value="<?= $name ?>

Is equivalent to this one :

<input type=text name="name" value="<?php echo $name; ?>

But only when short open tags are enabled.


And, as a sidenote : short open tags are not always enabled -- in fact, they are disabled by default, with recent versions of PHP.

Which means it might be wise to not depend on those, at least if you want to deploy your application on servers on which you are not administrator.

Pascal MARTIN
I agree, relying on short tags is asking for a broken heart when you deploy on a server that is configured to not allow them :)
JC
In defense of short tags, they're invaluable if you use PHP as its own templating layer. Additionally, it can be set PHP_INI_PERDIR -- i.e., in .htaccess on a per-app basis.
Frank Farmer