NameSilo

PHP short_open_tag

Namecheap AuctionsNamecheap Auctions
SpaceshipSpaceship
SpaceshipSpaceship
Watch

paaaaaaaaaa

Established Member
Impact
6
How often is this setting actually set to false?

In a project of mine i have been using the short hand <?= $var ?> to echo/print a variable. If anyone has experienced this being set to false or even better, has an idea of how often it is set to false then let me know, it would be of great help to me.
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
I have never come across it being disabled (or false as you put it) across a variety of servers, however when programming you should always assume that it will be off especially if you are coding commercially or anything that will be distributed.

You can't accurately say how often if will be enabled as put simply it's pot luck, i believe however it is set enabled by default.

Like i say, for anything cross platform/commercially distributed - use the long way (as I'm sure you know).
PHP:
<?php echo $var ?>
Matt.
 
Last edited:
0
•••
Yeah thats what I thought. I myself have not come across it being disabled (i said false by habbit, its actually 1/0). I've always used the echo method with the full php tags. Though I like to slim my code down as much as possible (I find myself using the Ternary Operator instead of if statements etc) and just wondered if using the short hand echo method would be benificial.

Like you said it is set to work by default but I'm sure there are many host out there that like to change things so I think I will just stick to using the long way. Thus less need for horrible "you need to contact your host to change their php.ini settings" support.
 
0
•••
I've never been on a server where it didn't work to date. But your code will be move readable using the long method.
 
0
•••
I'm not 100% sure but if I remember correctly in php 6 short tags will be disabled by default and asp style tags won't exist.

Although admittedly php 6 is some way off it could indicate they may disable them at a later stage in php 5.
 
0
•••
I use WAMP server and that turns them off by default which annoying so I always use the longhand so I know it will be compatible with all servers.
 
0
•••
Good feedback guys. Thanks

@ filth

No they will be keeping php short tags in php6. Support for ASP tags will be scrapped though.
 
0
•••
Through all the server admin work and PHP editing I've done, can't say that I've ever seen short_open_tag disabled. No reason for it to be.
 
0
•••
Tree said:
No reason for it to be.

Code:
<?php
// php code
?>
<?xml version="1.0"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" ...

A lot of lazy programmers will be doing a lot of search-and-replace in a couple of years.

I have it disabled on all of my servers.

No reason for it not to be. :)

Rich
 
0
•••
PHP:
<?='<?xml version="1.0"?>'?>
 
0
•••
tm said:
PHP:
<?='<?xml version="1.0"?>'?>

lol, that's PHP in a nutshell. I wondered if anyone would counter with that.

If inserting
PHP:
<?php echo ?>
takes more effort to insert in your scripts/pages than
PHP:
<?= ?>
, you need a new editor or learn how to use the one you have, because all it takes for me is a double-click for either.

I agree it sucks that <?= doesn't work when short tags are disabled but that's PHP, it sucks. Just like so many other php "features", it was stupid to have multiple variations of opening/closing tags.

If you're just hacking stuff together and don't care about portability, maintainence, or longetivity (hmmm, kinda like PHP itsself), the short open tags are fine.

The PHP developers are slowly removing/correcting all of the "features" that should never have been a part of the language so, if you want maximum portability, program as though short open tags are off.

I'll probably get a lot of flak, but 5 or 6 years ago you could have had an identical thread about register_globals.

hypothetical php thread said:
post#1 "anyone ever see register_globals turned off?"

post#2 "no, never. They're great, makes using PHP easy."

post#3 "you shouldn't use register_globals, too easy to write insecure code"

post#4 "you worry too much"

Rich
 
Last edited:
0
•••
paaaaaaaaaa said:
No they will be keeping php short tags in php6. Support for ASP tags will be scrapped though.


Yes double checked and you are indeed correct. Had it in my head for some reason that they were to get removed.

Tree said:
Through all the server admin work and PHP editing I've done, can't say that I've ever seen short_open_tag disabled. No reason for it to be.

php.net actually advises that you should not use short tags or asp style tags:-

Note: Using short tags should be avoided when developing applications or libraries that are meant for redistribution, or deployment on PHP servers which are not under your control, because short tags may not be supported on the target server. For portable, redistributable code, be sure not to use short tags.

http://www.php.net/manual/en/language.basic-syntax.php
 
0
•••
Rich_H said:
lol, that's PHP in a nutshell. I wondered if anyone would counter with that.

If inserting
PHP:
<?php echo ?>
takes more effort to insert in your scripts/pages than
PHP:
<?= ?>
, you need a new editor or learn how to use the one you have, because all it takes for me is a double-click for either.

I agree it sucks that <?= doesn't work when short tags are disabled but that's PHP, it sucks. Just like so many other php "features", it was stupid to have multiple variations of opening/closing tags.

If you're just hacking stuff together and don't care about portability, maintainence, or longetivity (hmmm, kinda like PHP itsself), the short open tags are fine.

The PHP developers are slowly removing/correcting all of the "features" that should never have been a part of the language so, if you want maximum portability, program as though short open tags are off.

I'll probably get a lot of flak, but 5 or 6 years ago you could have had an identical thread about register_globals.

Rich

I was just providing an alternative solution. I usually code with short tags because sofar I see no good reason why not to. If it's a piece of code which I mean to redistribute, then yes, I will use 'long' tags.
 
0
•••
tm said:
I was just providing an alternative solution. I usually code with short tags because sofar I see no good reason why not to. If it's a piece of code which I mean to redistribute, then yes, I will use 'long' tags.

I understand. I wasn't harping on you. I just think that it's best not to use short open tags at all. I haven't for quite a while, and now I don't even think of using them. They probably would have already been disabled by default or even removed if so much code didn't depend on them.

I fully agree that it's convenient to use <?= and it's incredibly stupid that it's disabled when short open tags are disabled. I haven't peered into the PHP source, but I would think it would be easy to allow the use of the echo shortcut with short open tags off.


Rich
 
Last edited:
0
•••
DomainEasy: white label portfolios are live. Enable yours.

We're social

Escrow.com
Spaceship
CryptoExchange.com
Domain Recover

NamePros updates

Portfolio sites: new ways to sort, filter and group your domains
Your public portfolio page has a few new tools for visitors. Portfolio: Newest first The sort menu now has "Newest first". It shows the...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back