|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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. |
|
#2
|
|||
|
|||
|
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; } } |
|
#3
|
|||
|
|||
|
Are you aware, that you could have put [ php ] [ /php ] around your PHP???? It would make it alot easier to read ;P
PHP Code:
If you wanted to for implementation of the of the interface methods, you might do this; PHP Code:
__________________
Eric Coleman - Co-Owner ZaireWeb Solutions eric.coleman@zaireweb.com http://sitemod.net - sitemodCMS Coming Soon! |
|
#4
|
|||
|
|||
|
BTW, that's his code, just a bit easier to read
![]() |
![]() |
| Viewing: Dev Articles Community Forums > Programming > PHP Development > Creating Interfaces in PHP |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|