PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old February 20th, 2003, 04:36 AM
walkintothelite walkintothelite is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Posts: 2 walkintothelite User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Creating Interfaces in PHP

I'm trying to move a system over to a Object oriented approach and want to find out if it is possible to create an interface in PHP similiar to the interfaces in JAVA?

There seems little resources on this on the web but it would appear to be something vitual in a develpoment enviroment.

Any questions on other object PHP stuff i'm happy to feed out my research.

Reply With Quote
  #2  
Old February 20th, 2003, 08:37 AM
walkintothelite walkintothelite is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Posts: 2 walkintothelite User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Interfaces in PHP: I found it in the end.... Bit messy, PHP really needs to update this inline with Java!

<?php
class Temperature {
var $value=0;
function Temperature($value) {
$this->value=$value;
}
function toCelcius() {}
function toFarenheight() {}
function getValue () {
$return $this->value;
}
}

class Celcius extends Temperature {
function Celcius($value) {
Temperature::Temperature($value);
}
function toCelcius() {}
function toFarenheight($value) {
return $this->value * 1.5;
}
}

class Farenheight extends Temperature {
function __construct($value) {
Temperature::Temperature($value);
}
function toCelcius() {
return $this->value / 1.5;
}
function toFarenheight($value) {}
}
?>
If you wanted to for implementation of the of the interface methods, you might do this;

class Temperature {
var $value=0;
function Temperature($value) {
$this->value=$value;
}
function toCelcius() {
die ( 'Method toCelcius not implemented' );
}
function toFarenheight() {
die ( 'Method toCelcius not implemented' );
}
function getValue () {
$return $this->value;
}
}

Reply With Quote
  #3  
Old February 20th, 2003, 01:47 PM
ZaireWeb ZaireWeb is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2002
Location: Hamburg, NY
Posts: 37 ZaireWeb User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to ZaireWeb Send a message via AIM to ZaireWeb
Are you aware, that you could have put [ php ] [ /php ] around your PHP???? It would make it alot easier to read ;P

PHP Code:
class Temperature {
    var 
$value=0;
    function 
Temperature($value) {
        
$this->value=$value
    }
    function 
toCelcius() {}
    function 
toFarenheight() {}
    function 
getValue () {
        
$return $this->value;
    }
}

class 
Celcius extends Temperature {
    function 
Celcius($value) {
        
Temperature::Temperature($value);
    }
    function 
toCelcius() {}
    function 
toFarenheight($value) {
        return 
$this->value 1.5;
    }
}

class 
Farenheight extends Temperature 
    function 
__construct($value) {
        
Temperature::Temperature($value);
    }
    function 
toCelcius() {
        return 
$this->value 1.5;
    }
    function 
toFarenheight($value) {}


If you wanted to for implementation of the of the interface methods, you might do this;
PHP Code:
class Temperature {
    var 
$value=0;
    function 
Temperature($value) {
        
$this->value=$value
    }
    function 
toCelcius() {
        die ( 
'Method toCelcius not implemented' );
    }
    function 
toFarenheight() {
        die ( 
'Method toCelcius not implemented' );
    }
    function 
getValue () {
        
$return $this->value;
    }

__________________
Eric Coleman - Co-Owner ZaireWeb Solutions
eric.coleman@zaireweb.com
http://sitemod.net - sitemodCMS Coming Soon!

Reply With Quote
  #4  
Old February 20th, 2003, 01:48 PM
ZaireWeb ZaireWeb is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2002
Location: Hamburg, NY
Posts: 37 ZaireWeb User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to ZaireWeb Send a message via AIM to ZaireWeb
BTW, that's his code, just a bit easier to read

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingPHP Development > Creating Interfaces in PHP


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT