Tag <? PHP problem

I work with legacy code that someone left, and my task is to redeploy the code. I am using Windows Server 2003, Apache 2.0.63 and PHP 5.2.10.

This does not work. At least not as I expected it to work. Call it bugs if you want.

When checking, I had a suspicion that this code (which appears many times in the application) is the culprit.

  & $ this->

To illustrate the problem, I reproduce this code:

  <? php
        phpinfo ();
        // $ variable = & $ this-> request;
     ?>

The above code is executed beautifully and as expected. However, if I changed the code to:

  <?
        phpinfo ();
        // $ variable = & $ this-> request;
     ?>

The code does not work correctly and produces this result on the screen instead, which, of course, is completely undesirable and unexpected.

  request;  ?>

Now the code is littered with the same code as above, and thus the application now displays a screen similar to this:

  request;  $ user = & $ this-> user;  // This is comment return false;  ?>

for code that reads like:

  <?
         $ request = & $ this-> request;
         $ user = & $ this-> user;
         // This is comment
         return false;
     ?>  

I tried to change every <? with <? php when & $ this-> returns its ugly head, but most of the time it introduces a new error.

I reinstalled PHP and Apache, even using a different version of PHP (5.2.6), and it still won't work. I deployed the code in my local host (Mac OS X, PHP 5.2.8 and Apache 2.0.63) and it worked without hassle.

Please, no one, more than enough enlightenment.

+4
php
source share
3 answers

In php.ini you need to install the following directive:

short_open_tag = On 

From manual :

Reports whether the short form ( <? ?> ) Of an open PHP tag ...

If you have time on your hands, you may want to replace all those short tags with <? to full-length <?php , for better portability (see what just happened to you? :)

+12
source share

my recommendation is not to use open tags, because it can interfere with <?xml codes. I also had this problem before, just replace all <?php with <? and then again all <? on <?php .

So you do not get any

 <? <-- one space after the '?' 

and

 <?php <-- one space after the 'p' 

hope this helps ...

+2
source share

If you want to use short tags: ("<?")

they must be included in php.ini. See Link.

0
source share

All Articles