Examples Of Using Inherance And Interfaces In PHP 5

Jul 17, 2005

As many of you knows, Zend has relased the Beta version of PHP 5. I
have allready make some tests of interfaces, classes inherance, static
and public variables, etc, and everything looks ok. Now, when you work
with PHP the most common thing is to do something with databases, you
have somehow the "same kind of pattern" like: logins, update, add,
delete data from de db, show data and that is it.

Now, I will like to use the new PHP 5 features in my next project. I
was trying to desing some clases and inferfaces for the "pattern" that
PHP use to have, and have not come with any good worthy idea. I know
Java too, so I was very happy about the the new features in PHP5 and
looking to use object model features. Im looking for very clear
examples on, how you have used the new features in PHP5 to do the "old
PHP thing"?

View 1 Replies


Use Interfaces In OOP?

Why do we use interface in OOP?...I am really having hard time to grasp this concept..I would really be grateful appreciate if somebody provided me a better answer for this...

View 2 Replies

What Is The Purpose Of Interfaces ?

If I define an interface in PHP, and a factory class that creates an instance of that interface, is there any way I can force client code to only use the interface and not the underlying concrete class? From my understanding, the clients are able to actually use any public functions/fields in the underlying class as well.Here is an example:

interface IMyInterface
public function doSomething();[code]....

View 4 Replies

Use Fields In Interfaces?

In PHP, can I specify an interface to have fields, or are PHP interfaces limited to functions?

interface IFoo
public $field;
public function DoSomething();
public function DoSomethingElse();

If not, I realize I can expose a getter as a function in the interface:

public GetField();

View 3 Replies

Oop - Use Interfaces In Codeigniter?

I am trying to find out how can I used PHP interfaces in my MVC design. I want to make sure that the design enforces an interface so that any new module would follow that.For example:

interface BaseAPI {

View 2 Replies

Get A List Of Network Interfaces In PHP?

I've got a utility I'm working on, and I want to be able to list for
the user all the current network interfaces on the machine. Is there a
way to do this in PHP? PHP 5.0.3, Mandriva Linux 2005 (2.6 kernel).
I'm not actually in front of the machine in question, and I don't
recall the minor kernel version, or the minor version of Mandriva...

Any thoughts? I'd prefer not to have to run the script as root,
incidentally. I realize I could run as root and then just parse the
output of ifconfig, but I assume there's a more intelligent way to go
about what I'm trying to do.

The purpose of this utility is to allow me to issue a ping, from a
specified interface (including virtual interfaces, e.g., eth0:1), and
test for connectivity from the webserver to the the address i am
pinging, through the specified network interface (rather than always
pinging from the default/primary interface of the machine).

Any thoughts? How would I go about this? I haven't been able to come
up with a way to do this, short of running as root and parsing
ifconfig, as I mentioned above.

View 2 Replies

Java Or PHP 5.0 Question About Interfaces

Do interfaces enforce how many arguments can be passed to a method? If
two classes inherit from the same interface, can one have
formatThisText($text) and another have formatThisText($text,
$formatter) ??? I'm assuming the answer is yes, interfaces do enforce
the number of arguments.

View 2 Replies

Standard Interfaces And Objects? (Where Are They?)

I was wondering if there is a list some place of the standard interfaces
that are internal to PHP.

Specifically, I was looking for the docs on Iterators.

Is there a URL (or good search terms) one can use to find a list
of them?

View 2 Replies

Use Interfaces And Magic Methods?

I want to use interfaces, but some of my implementations rely on magic methods such as __invoke and __call. I have to remove signatures of methods that may be invoked magically (in any implementation) from the interface. Which leads to the anti pattern Empty Interface (Yeah, I just made that up).How do you combine interfaces and magic methods in PHP?

View 1 Replies

Find Template Interfaces?

i wonder where one can find template interfaces.eg. i am creating these classes that implements iLog:


i wonder what methods should a typical Log class have?is there a set of interfaces you could just implement/learn from rather than reinvent the wheel and have to think about the method names.

View 1 Replies

Oop - Cannot Implement Two Interfaces That Have The Same Method Name?

This doesn't work:

interface TestInterface
public function testMethod();


View 5 Replies

Create Point Of Interfaces?

Possible Duplicate: What is the point of interfaces in PHP? Why should I create Interfaces in PHP?As I understands, interfaces are there to describe classes that implement them. The classes have to contain at least these functions. This is all fine if you're building upon someone else's work, or have to maintain a degree of compatibility. But in more simplistic cases?I know, that for the compiled programming languages, like C++, usage of interfaces allows for an increase in compiling speed, but what about PHP? This advantage seems to disappear, since PHP is interpreted, rather than compiled.

View 4 Replies

What Are The Differences Between Abstract And Interfaces

A abstract class and a interface are basically the same thing except you can use multiple interfaces in one class. What are the differences? and what is its application?

View 9 Replies

Are Drupals Hooks An Implementation Of Interfaces

It seems to me that when creating a module you are using Drupal's hooks like an interface, typically the interface that you implement forces the same method names but could it be said that the naming conventions that Drupal institutes conform to this design pattern?

View 1 Replies

Django - Build Admin Interfaces?

What's the quickest way to build admin interfaces in PHP?

It can be a framework, a library/libraries coupled with a particular approach, or whatever.

Background: I'm a Django developer spoiled by auto admin who has to deliver a web-app in PHP. The app is very admin-area/form heavy and has different access levels.

View 6 Replies

What Is The Intent Of Using Abstract Classes Vs Interfaces

Abstract Classes and Interfaces...

1.) When you have an Interface with Methods, then any Concrete Class that "implements" said Interface must include all of the listed Methods, correct?

2.) When you have an Abstract Class with Properties & Methods, are you required to use all of the listed Properties & Methods similar to how an Interface works?

3.) What is the intent of using Abstract Classes vs. Interfaces?

View 9 Replies

GD Module Examples

Anyone here used, or is using PHP's GD module in their web design? I would be real interested in seeing what anyone has done with it on their web site with perhaps some sample code which demonstrates how they did it.

View 1 Replies

E-Mailing Examples Help.

I have created a form, which will allow a person to upload a picture,
and leave me mail. What I am having problems doing is, having the
form actually upload the picture and attach it to an email that is
then sent to me. If anyone knows of any sample code I could look at,

View 1 Replies

Pagination Examples

Basically im asking if anybody knows of any example code or tutorials where i can learn how to paginate a PHP page. I have a mySQL news table which holds stories as mark up. Ive had a look at a few examples and tutroials but most seem to have the the pages of the story in seperate rows in the database. Im also just confusing my self now with the multitude of options. Im using e107 as the back end by the way.

View 1 Replies

Printing Examples

Does anyone have any examples of how to send web page content to the
printer? I've looked at the PHP manual and I think I know how to do it
but I'd like be sure:

I have to open the printer first
Then I use the print write call?
Then I close the printer

View 4 Replies

Pagination Tried Several Examples

I'm having some difficulties with php pagination. I tried several sample codes provided on the net but none worked.

View 3 Replies

Type Hinting For Multiple Unrelated Interfaces?

Is there a way in php to type hint for two different, unrelated interfaces? For example:

interface errorable {
function error($msg);
interface recordable {

As you can see in the above code, the recorder class expects its module to have the ability to run both error() and ssh_for_recorder(), but these are defined by different interfaces. errorable need not be recordable and vice versa either. I was thinking of creating an interface that extends from recordable and errorable and having upload__module implement that, but I don't know what to call it.

View 2 Replies

Interfaces In Dynamic / Loosely - Typed Languages?

I work in php, and the concept of interfaces seems to me a little useless here. From reading, I understand that interfaces are part of "design by contract", but without at least guaranteeing a return of a type of a particular kind, there really isn't any contract. It seems it's like a contract that reads, "We agree to do the following: '' " -- there are no terms of the agreement.

If I want a guarantee that an object has a method, it doesn't seem like interfaces are particularly useful. If I try to call a method that an object doesn't have, I get a Fatal Error, so I find out pretty quickly that that class doesn't have a method with that name. If I want to be smart and check beforehand whether a class has a method, then checking the interface, and seeing whether the object implements that interface doesn't seem to save me any more time than just checking that object directly ( which I would do anyways to see if the class had that method regardless of any interfaces it did or didn't implement).

In other words, just because I have a set of methods that have particular names, that doesn't guarantee me any particular behavior. If I'm guaranteed a return of a variable of a certain type, I at least have some inkling of what the output would be, and I can write code that uses an object with that interface, because I know what I'm getting out of it. If it returns a string, I can continue coding with at least the certainty that I'm dealing with a string output afterward. So I'm guaranteed at least some behavior when a return type is specified. Is guaranteeing behavior part of what interfaces are for, or no?

The only thing I can think of is that when I'm writing code, it serves as a post-it note to myself to be sure to create certain methods when writing that class later on. It seems more like scaffolding for when I'm writing the code; I don't see much benefit from when I'm actually using it. So it's more for me to keep the standard when I'm creating classes than when I'm writing them. This benefit doesn't really seem to be captured in the concept of design by contract.

What benefit(s) do you actually get from using an interface in dynamic/loose-typed languages like PHP? Are they great, or is it something that more robust OO languages implement, so PHP implements it also?

View 4 Replies

Getting Information Of Currently Configured Network Interfaces On Linux?

I am encountering a problem with string formatting while trying to get only the names of currently configured network interfaces on a Linux Machine.

1. <?php
2. $temp = shell_exec("/sbin/ifconfig | cut -b 1-10");
3. echo $temp; //Outputs: eth0 lo
4. $arr = explode(" ",$temp);
5. echo "First Location:".$arr[0]; //Outputs: eth0

but i am doing something wrong while executing it from a php file because the browser does not show anything.

$temp = shell_exec("ifconfig | grep -o -e "[a-z][a-z]*[0-9]*[ ]*Link" | perl -pe "s|^([a-z]*[0-9]*)[ ]*Link|\1|"");
echo $temp;

View 2 Replies

Type Hinting Not Getting Along With Interfaces And Abstract Classes?

I think it'll be much easier to see the problem in a code example than writing the question in the first place. Here is my php code:

interface AnInterface
public function method();
class AClass implements AnInterface
public function method()

The problem is that php doesn't seem to be recognizing the signatures of AnAbstractClass::method and ConcreteClass::method as compatible. Am I doing something wrong?

View 2 Replies

Predefined Interfaces & SPL - Version Check Sufficient?

This is perhaps an obvious question, but I want to be sure. I'm trying to work out in which version the "Predefined Interfaces" appeared in PHP. My assumption is 5.0.0, as this is when the SPL interfaces were added according to the docs. Furthermore, can these ever be disabled via configuration or recompile, or can one safely assume a version check satisfies their presence? Why are they even separated from the SPL, is the differentiator just that these can't ever be turned off, whilst the SPL can be? (at least prior to 5.3.0)

View 3 Replies

Copyrights 2005-15 www.BigResource.com, All rights reserved