To register for an Internet.com membership to receive newsletters and white papers, use the Register button ABOVE.
To participate in the message forums BELOW, click here
PHPBuilder.com  
 

 

Go Back   PHPBuilder.com > PHP Help > Upgrading PHP

Upgrading PHP Issues concerning PHP version upgrades and future releases

Reply
 
Thread Tools Rate Thread Display Modes
Old 09-08-2004, 03:37 PM   #1
Nate
2+2=5
 
Join Date: Aug 2002
Location: Washington
Posts: 169
What are object interfaces?

http://us2.php.net/manual/en/languag...interfaces.php

I'm trying to understand what these are used for... Could someone explain that first sentence on that page to me in laymen's terms?

Thanks!
Nate is offline   Reply With Quote
Old 09-08-2004, 06:02 PM   #2
Weedpacket
Custom User Title™
 
Weedpacket's Avatar
 
Join Date: Aug 2002
Location: Rapid Offensive Unit "Foreign Object Damage"
Posts: 19,126
They're largely a self-documenting device for the benefit of programmers. An object interface is a list of functions that any class implemeting it must supply code for. If you're writing a class that implements the Foobar interface, and the Foobar interface lists a function called "super_foonly()" but you accidentally forget to write that function, PHP will throw an error.

The other side of the coin is that if you write an object interface, you can be assured that any class written implementing that interface will have the functions listed and you can therefore call them, assured that they will be there.
__________________
On two occasions I have been asked [by Members of Parliament], "Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?" I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question.
Weedpacket is offline   Reply With Quote
Old 09-08-2004, 06:13 PM   #3
Nate
2+2=5
 
Join Date: Aug 2002
Location: Washington
Posts: 169
Thanks! That makes perfect sense.
Nate is offline   Reply With Quote
Old 09-09-2004, 04:54 AM   #4
Weedpacket
Custom User Title™
 
Weedpacket's Avatar
 
Join Date: Aug 2002
Location: Rapid Offensive Unit "Foreign Object Damage"
Posts: 19,126
One other use of interfaces I forgot to mention is that your program can check to see if an object implements a particular interface in the same way that it can ask that object what class it is (or is descended from).

If an object implements the FooBar interface, then your code can check that it does by using ($object instanceof FooBar). The result will be true or false.

The same check can be made at runtime when the function is called:

function your_function(FooBar $object)
{
....
}

and if $object doesn't implement the FooBar interface, then when your_function() is called, PHP will whinge.
__________________
On two occasions I have been asked [by Members of Parliament], "Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?" I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question.

Last edited by Weedpacket; 09-09-2004 at 04:59 AM.
Weedpacket is offline   Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT -4. The time now is 11:16 PM.






Acceptable Use Policy

internet.comMediabistrojusttechjobs.comGraphics.com

WebMediaBrands Corporate Info


Advertise | Newsletters | Feedback | Submit News

Legal Notices | Licensing | Permissions | Privacy Policy


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.