PHP 4 and 5 compatibility issues

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
hempheastus
Forum Newbie
Posts: 3
Joined: Wed Feb 28, 2007 7:15 pm

PHP 4 and 5 compatibility issues

Post 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.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post 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';
}
(#10850)
User avatar
AKA Panama Jack
Forum Regular
Posts: 878
Joined: Mon Nov 14, 2005 4:21 pm

Post 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. :)
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

AKA Panama Jack wrote:You got those reversed. :)
Yes, it is !right. :)
(#10850)
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post 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 :?:
User avatar
Oren
DevNet Resident
Posts: 1640
Joined: Fri Apr 07, 2006 5:13 am
Location: Israel

Post 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)
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

version_compare() is a pretty simple addition. ;)
Post Reply