Page 1 of 1
<? vs <?php
Posted: Mon Mar 16, 2009 2:42 pm
by danpai
Hi all.
I just started working with a new client and they are using off-shore developers.
All the PHP files they sent me start with <? instead of <?php
My environment doesn't seem to like that too much. (I'm using PHP 5 on a Windows OS.)
So my questions are as follows:
1) Is there some reason to use <? vs <?php ?
2) Instead of doing a massive search and replace, is there any file I can update (php.ini or other) that would get me up and running?
Thanks in advance.
Dan
Re: <? vs <?php
Posted: Mon Mar 16, 2009 2:46 pm
by John Cartwright
Sounds like your server has short tags off, and they are developing with short tags on. It is generally good practice to code without short tags because, as you've noticed, some setups will have it disabled.
I would suggest you fix all your short tags by converting them to long tags, then ask these offshore developers to use long tags.
Of course the easy fix would be to enable short tags on your server.
Re: <? vs <?php
Posted: Mon Mar 16, 2009 2:54 pm
by danpai
John, thank you very much for your quick response. Exactly what I needed to know.
Dan
Re: <? vs <?php
Posted: Mon Mar 16, 2009 2:58 pm
by crazycoders
Another reason although i'm not too sure how to explain it is that it's all to do with XML files. If remember right, XML files start with <? too and it's not a good idea to start your php blocks with this or a future webserver could confuse your <? tag with the XML start tag...
At least, thats what i heard of.
I also remember that when short tags are on in the php engine, i got errors when processing XML files. This might explain better what i tried to explain look at this:
Code: Select all
<?xml version="1.0" encoding="UTF8"?>
<news>
<?php foreach($news as $article){ ?>
<newsarticle>
<id><?php echo utf8_encode($article['id']); ?></id>
<published><?php echo utf8_encode(substr($article['published'], 0, 10)); ?></published>
<title><?php echo utf8_encode($article['title']); ?></title>
<description><?php echo utf8_encode($article['description']); ?></description>
<iconid><?php echo utf8_encode($article['iconid']); ?></iconid>
</newsarticle>
<?php } ?>
</news>
Imagine now that your short open tag is on in this page... it will always report an error at line #1 stating that T_STRING version was unexpected. Thats because the code between <? ?> are not valid in this context...
Also understand that it was an error provoqued by me, because normally speaking, XML files do not trigger the PHP parser, but for this specific project and folder i embedded php instead the XML file (i did not show everything in there)