4

I'm working with a legacy code that someone had left, and it happens to be my task to re-deploy the code. I'm using Windows Server 2003, Apache 2.0.63 and PHP 5.2.10.

It doesn't work. At least, not in the way I had expected it to work. Call it bugs, if you will.

Upon inspecting, I had a suspicion that this code (which appears numerous times in the application) is the culprit.

    &$this->

To illustrate the problem, I reproduce this code:

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

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

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

The code misbehaves, and produce this result on the screen instead, which of course, totally unwanted and unexpected.

    request; ?>

Now, the code is littered with the similar code as above, and as such, the application now produce output on the screen similar to this one:

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

for a code that reads as:

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

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

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

Please, anyone, any enlightenment will more than suffice.

Rhama Arya Wibawa
  • 250
  • 1
  • 2
  • 15

3 Answers3

12

In your php.ini, you need to set the following directive:

short_open_tag = On

From the manual:

Tells whether the short form (<? ?>) of PHP's open tag should be allowed...

If you have time on your hands, you may want to consider replacing all those short tags '<?' with the full-form ones <?php, for better portability (see what just happened to you? :)

karim79
  • 339,989
  • 67
  • 413
  • 406
  • @karim79, I had tried to do that, but most of the times, it complains about &$this not being bla...bla...bla... Plus, it's not my code, and you know how it is to work with someone else's codes. – Rhama Arya Wibawa Aug 14 '09 at 02:38
  • @Rhama Arya Wibawa - can you please paste the error in your question or here – karim79 Aug 14 '09 at 02:40
  • @karim79 well, the error was recorded in the Apache's error_log (it's not there anymore as I had deleted the previous Apache's installation folders) and now that it has been fixed, albeit using method that isn't really recommended, I'm not eager to reproduce the error. :( – Rhama Arya Wibawa Aug 14 '09 at 04:54
  • @Rhama Arya Wibawa - it's not a big deal, the important thing is you got it working :) I just mentioned that for information purposes, I wasn't trying to make you feel bad. – karim79 Aug 14 '09 at 05:02
2

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

In this way you won't get any

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

and

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

hope this will help...

Shir Gans
  • 1,976
  • 3
  • 23
  • 40
0

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

they need to be enabled in you php.ini. See this link.

Steven
  • 3,813
  • 2
  • 22
  • 27