the short hand php opening tag '<?' !!!
Moderator: General Moderators
-
lauthiamkok
- Forum Contributor
- Posts: 153
- Joined: Wed Apr 01, 2009 2:23 pm
- Location: Plymouth, United Kingdom
the short hand php opening tag '<?' !!!
Very often, when I am passed on a php-based project from another developers, I come across <? as an alternative short version of the php opening tag and it never works on my local server.
I wonder why these programming background php developers tend to do this instead of typing a full tag. I am a designer background php developer.
Also, I come across this very often which puzzles me,
<?= bloginfo('template_directory'); ?>
Is anyone can advise me how to make this short hand tag <? and <?= to work on my local server? Or please advice what I can do about them? should I change these two type of short hand to <?php ;?> ?
Many thanks,
Lau
I wonder why these programming background php developers tend to do this instead of typing a full tag. I am a designer background php developer.
Also, I come across this very often which puzzles me,
<?= bloginfo('template_directory'); ?>
Is anyone can advise me how to make this short hand tag <? and <?= to work on my local server? Or please advice what I can do about them? should I change these two type of short hand to <?php ;?> ?
Many thanks,
Lau
- greyhoundcode
- Forum Regular
- Posts: 613
- Joined: Mon Feb 11, 2008 4:22 am
Re: the short hand php opening tag '<?' !!!
You will probably need to adjust your php.ini settings, you can view the notes on this here.
Hopefully not teaching you to suck eggs (but you did say you found it confusing) - the <?= tag simply echoes the variable (or output from a function) that follows it:
Hopefully not teaching you to suck eggs (but you did say you found it confusing) - the <?= tag simply echoes the variable (or output from a function) that follows it:
Code: Select all
<?php $string = 'Hellooo!'; ?>
<?= $string; ?>
<?php
// Or, long-hand
echo $string;
?>
Last edited by greyhoundcode on Wed Apr 01, 2009 2:59 pm, edited 1 time in total.
Re: the short hand php opening tag '<?' !!!
you should change them ALL to <?php.
- greyhoundcode
- Forum Regular
- Posts: 613
- Joined: Mon Feb 11, 2008 4:22 am
Re: the short hand php opening tag '<?' !!!
Worth pointing out that although many people say you should use the full tags <?php ?> other sources, such as the CodeIgniter docs, suggest otherwise.
Re: the short hand php opening tag '<?' !!!
well, when you get your codes into a host with strict php settings where <? short cuts not allowed, with your boss/client anxiously waiting, you will know what i mean. code igniter or whatever else by that time is not in any way responsible.
it is rare, but it does happen, and you do not want to get caught in one of those nets.
it is rare, but it does happen, and you do not want to get caught in one of those nets.
-
lauthiamkok
- Forum Contributor
- Posts: 153
- Joined: Wed Apr 01, 2009 2:23 pm
- Location: Plymouth, United Kingdom
Re: the short hand php opening tag '<?' !!!
thanks for the tips guys. will amend the php.ini
as for the best practise for me, i think i wont use short hand for php - it looks amateur.
as for the best practise for me, i think i wont use short hand for php - it looks amateur.
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
Re: the short hand php opening tag '<?' !!!
I have short_open_tag turned off in php.ini, then any sites that need it I drop in a .htaccess rule just for that site:
Code: Select all
php_flag short_open_tag onRe: the short hand php opening tag '<?' !!!
As does the Zend framework. I used to be majorly against the use of short open tags, but in templates, it's just much more convenient. I always use my own server, so I haven't had issues where I couldn't get short open tags turned on, but it is a perfectly valid argument. It would majorly suck if your host refused to let you have open tags and you had an app littered with them.greyhoundcode wrote:Worth pointing out that although many people say you should use the full tags <?php ?> other sources, such as the CodeIgniter docs, suggest otherwise.
Re: the short hand php opening tag '<?' !!!
I've always thought the opposite.lauthiamkok wrote: i think i wont use short hand for php - it looks amateur.
Could just replace all and fix it in a second.Luke wrote: It would majorly suck if your host refused to let you have open tags and you had an app littered with them.
Re: the short hand php opening tag '<?' !!!
maybe you have clients most understanding and appreciate of your efforts to get things working.divito wrote:Could just replace all and fix it in a second.
Re: the short hand php opening tag '<?' !!!
Er, I meant using a "Replace All" function like the one in Dreamweaver, <? to <?php.
Re: the short hand php opening tag '<?' !!!
ok, so you have clients like mine then. 
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
Re: the short hand php opening tag '<?' !!!
Until you need to use <?xml ?> in your template.Luke wrote:I used to be majorly against the use of short open tags, but in templates, it's just much more convenient.
I agree that we can't completely remove them just yet since so many public domain apps are littered with them, but I don't think they're better than full tags and I don't think we should be using them for new projects.
I was quite surprised to see ZF advocating the use of them.
Just my $0.02.
- greyhoundcode
- Forum Regular
- Posts: 613
- Joined: Mon Feb 11, 2008 4:22 am
Re: the short hand php opening tag '<?' !!!
Horses for courses and all that.
Like Divito and Luke (if I understood you guys correctly!) I quite like short tags in templates. Nice and clean and tidy, but yeah the problems with some hosts are apparent.
Thing is, the likes of the OP isn't uncommon, and you often see a lot of responses along the lines of, "No, never use short tags! They're evil!" But there are valid reasons for using them, whether you agree on a personal level or not, and so long as people get the full picture they can doubtless make their own minds up.
Like Divito and Luke (if I understood you guys correctly!) I quite like short tags in templates. Nice and clean and tidy, but yeah the problems with some hosts are apparent.
Thing is, the likes of the OP isn't uncommon, and you often see a lot of responses along the lines of, "No, never use short tags! They're evil!" But there are valid reasons for using them, whether you agree on a personal level or not, and so long as people get the full picture they can doubtless make their own minds up.
Re: the short hand php opening tag '<?' !!!
It's still a pain in the butt if you need to move several projects to a different configuration etc. I never use short tags.divito wrote:Er, I meant using a "Replace All" function like the one in Dreamweaver, <? to <?php.