conditional "implements"

This is a discussion on conditional "implements" within the PHP Language forums, part of the PHP Programming Forums category; Hi there! Currently i'm thinking about how to solve this problem: if (t3lib_div::int_from_ver(phpversion())<5000000) { // php4 class ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 06-28-2007
Christian Welzel
 
Posts: n/a
Default conditional "implements"

Hi there!

Currently i'm thinking about how to solve this problem:

if (t3lib_div::int_from_ver(phpversion())<5000000) {
// php4
class tx_lib_object extends tx_lib_selfAwareness {...}
//
} else {
// php5
class tx_lib_object extends tx_lib_selfAwareness implements ArrayAccess, Iterator {...}
//
}

The question is now how to make this conditional "implements" in php?
Of cause i do not want to copy the code for both php versions and then
switch between the whole classes.

--
MfG, Christian Welzel aka Gawain@Regenbogen

GPG-Key: http://www.camlann.de/key.asc
Fingerprint: 4F50 19BF 3346 36A6 CFA9 DBDC C268 6D24 70A1 AD15
Reply With Quote
  #2 (permalink)  
Old 06-28-2007
ZeldorBlat
 
Posts: n/a
Default Re: conditional "implements"

On Jun 28, 3:36 pm, Christian Welzel <gaw...@camlann.de> wrote:
> Hi there!
>
> Currently i'm thinking about how to solve this problem:
>
> if (t3lib_div::int_from_ver(phpversion())<5000000) {
> // php4
> class tx_lib_object extends tx_lib_selfAwareness {...}
> //} else {
>
> // php5
> class tx_lib_object extends tx_lib_selfAwareness implements ArrayAccess, Iterator {...}
> //
>
> }
>
> The question is now how to make this conditional "implements" in php?
> Of cause i do not want to copy the code for both php versions and then
> switch between the whole classes.
>
> --
> MfG, Christian Welzel aka Gawain@Regenbogen
>
> GPG-Key: http://www.camlann.de/key.asc
> Fingerprint: 4F50 19BF 3346 36A6 CFA9 DBDC C268 6D24 70A1 AD15


Create two different classes (the PHP5 version which extends the PHP4
version and implements the interfaces) then instantiate the proper one
using some sort of factory method. Other than the fact that the PHP5
version implements your interfaces, the classes will behave in exactly
the same way. For example:

class tx_lib_object extends tx_lib_selfAwareness {
//All the tX_lib_object methods

//The factory:
public static factory() {
if(t3lib_div::int_from_ver(phpversion())<5000000)
return new tx_lib_object();
else
return new tx_lib_object_php5();
}
}

if(t3lib_div::int_from_ver(phpversion())>=5000000) {
class tx_lib_object_php5 extends tx_lib_object implements
ArrayAccess, Iterator {
//all the methods to implement ArrayAccess and Iterator
}
}

Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 04:52 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0