Page 1 of 1

PHP 4 and 5 compatibility issues

Posted: Wed Feb 28, 2007 7:29 pm
by hempheastus
Ok, basically what I am wondering is if there is a equivalent PHP "thing" to the "preprocessor directives" one can use in C/C++. I know that PHP is not compiled and hence no preprocessing. So, maybe it would be better if I explained exactly what I am trying to do.

I have several classes which are written for PHP 5, and I would like to make them compatible with PHP 4. Now, for the most part they are compatible, but in areas of class definitions is where I get my errors. So here is an example of what I want to do.

*** PLEASE USE CODE TAGS ***
---------------------------------------------------------------------
PHP 5 code:

Code: Select all

class test1
{
  private $a;
  private $b;

  //declare functions below
}
PHP 4 code:

Code: Select all

class test1
{
  var $a;
  var $b;

  //declare functions below
}
What I want to happen (SUDO-CODE):

Code: Select all

class test1
{
  if(!thisIsPHP5)
  {
    var $a;
    var $b;
  }
  else
  {
    private $a;
    private $b;
  }

  //declare functions below
}
---------------------------------------------------------------------
Now, I know the PHP 4 code is compatible with PHP 5, but I would like to be able to use the private/public keywords if capable.

Anyways, I would appreciate any light anyone could shine on this. If this question has already been answered somewhere on the forum, I appologize for not search and finding it, but I do not even know what keywords I could use to find this.

Posted: Wed Feb 28, 2007 9:59 pm
by Christopher
You really can't do that within the code, but you could do:

Code: Select all

if(!thisIsPHP5) {
     include 'test_5.php';
} else {
     include 'test_4.php';
}

Posted: Wed Feb 28, 2007 11:15 pm
by AKA Panama Jack
arborint wrote:You really can't do that within the code, but you could do:

Code: Select all

if(!thisIsPHP5) {
     include 'test_5.php';
} else {
     include 'test_4.php';
}
You got those reversed. :)

Posted: Thu Mar 01, 2007 12:58 am
by Christopher
AKA Panama Jack wrote:You got those reversed. :)
Yes, it is !right. :)

Posted: Thu Mar 01, 2007 2:22 am
by Chris Corbyn
/me starts to ponder if doing something like this could stop my gazillions of support requests from people saying they got parse errors trying to run my PHP5 code in PHP4 :?:

Posted: Thu Mar 01, 2007 5:15 am
by Oren
d11wtq wrote:/me starts to ponder if doing something like this could stop my gazillions of support requests from people saying they got parse errors trying to run my PHP5 code in PHP4 :?:
Well, that had happened to me too... But only because of a misunderstood between me and my host (= a friend of mine :P)

Posted: Thu Mar 01, 2007 8:47 am
by feyd
version_compare() is a pretty simple addition. ;)