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"?

ADVERTISEMENT

Use Interfaces In OOP?

Jan 27, 2009

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 View Related

What Is The Purpose Of Interfaces ?

Dec 7, 2010

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:

<?php
interface IMyInterface
{
public function doSomething();[code]....

View 4 Replies View Related

Use Fields In Interfaces?

Feb 12, 2010

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

<?php
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 View Related

Oop - Use Interfaces In Codeigniter?

May 16, 2010

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:

<?php
interface BaseAPI {
[code].........

View 2 Replies View Related

Get A List Of Network Interfaces In PHP?

Oct 23, 2006

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 View Related

Java Or PHP 5.0 Question About Interfaces

Jul 17, 2005

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 View Related

Standard Interfaces And Objects? (Where Are They?)

Jul 17, 2005

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 View Related

Use Interfaces And Magic Methods?

Feb 11, 2011

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 View Related

Find Template Interfaces?

May 3, 2010

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

DatabaseLog
ScreenLog
FileLog

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 View Related

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

Mar 31, 2011

This doesn't work:

interface TestInterface
{
public function testMethod();

[code]...

View 5 Replies View Related

Create Point Of Interfaces?

Nov 13, 2010

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 View Related

What Are The Differences Between Abstract And Interfaces

May 17, 2009

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 View Related

Are Drupals Hooks An Implementation Of Interfaces

Nov 6, 2010

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 View Related

Django - Build Admin Interfaces?

Mar 9, 2009

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 View Related

What Is The Intent Of Using Abstract Classes Vs Interfaces

Oct 28, 2010

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 View Related

GD Module Examples

Jan 8, 2002

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 View Related

E-Mailing Examples Help.

Jul 17, 2005

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 View Related

Pagination Examples

Jun 7, 2006

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 View Related

Printing Examples

Jul 17, 2005

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 View Related

Pagination Tried Several Examples

May 12, 2007

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

View 3 Replies View Related

Type Hinting For Multiple Unrelated Interfaces?

Mar 1, 2011

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

interface errorable {
function error($msg);
}
interface recordable {
ssh_for_recorder();
}...........

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 View Related

Interfaces In Dynamic / Loosely - Typed Languages?

Aug 25, 2010

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 View Related

Getting Information Of Currently Configured Network Interfaces On Linux?

Nov 1, 2009

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
code....

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

<?php
$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 View Related

Type Hinting Not Getting Along With Interfaces And Abstract Classes?

Dec 30, 2010

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:

<?php
interface AnInterface
{
public function method();
}
class AClass implements AnInterface
{
public function method()
[Code]....

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 View Related

Predefined Interfaces & SPL - Version Check Sufficient?

Apr 5, 2011

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 View Related

Point Of Interfaces In A Weekly-typed Language?

May 3, 2010

I've never been able to figure this out. If your language doesn't type-check, what benefits do interfaces provide you?

View 9 Replies View Related

Looking For Examples Of Huge MySQL & PHP

Mar 28, 2000

Does anyone know of any existing operational web sites where a massive (ie. millions of records) MySQL database combines with PHP to provide a directory service? I'm thinking along the lines of the White or Yellow Pages or similar. I ask because I'm researching a project which provides a (large) web-based specialist directory service, and I'd like to be in contact with people who've already done it with MySQL and PHP. I use MySQL and PHP all the time for small applications, but I'm not sure how they compare (in terms of speed and reliability) in the commercial world against the expensive alternatives.

View 1 Replies View Related

PHP Tutorial Or Project Examples

Sep 19, 2005

I've worked with ASP, ASP.NET and
WebSpeed in the past, but now I'd like to learn PHP. I've already
gotten a Fedora web server up and running with Apache and MySQL.

I'm looking for some examples - or even better a free project - to look
over and see how other are using PHP to read/write records to and from
MySQL. I'm trying to create a very simple web based contact management
system that will store data in a couple of tables.

Can someone recommend any examples or web sites to refer to? I'm about
to dive into the PHP manual, but I'd like some other material to study
as well.

View 5 Replies View Related

Examples Of Autoloading Object

Feb 12, 2007

I'm a bit confused with autoloading objects.

This is only for PHP5, correct?

All autoloading functions start with "__" correct?

And can someone give me a easy to understand example of an autoloading object? I googled, but I still have questions about it.

View 1 Replies View Related

MySQL Transactional Examples

Jul 17, 2005

Does anyone have any examples of using Transactional processing of
MySQL with PHP? I'm not sure if the BEGIN statement needs to be in
front of my SELECT statement or processed before hand by itself.

View 1 Replies View Related

Any App Examples For Propel & Zend

Oct 26, 2010

I found a few Zend sample applications but all of them use Zend_DbTable. Does anyone know of a full Zend example application built with Propel to learn from?

View 1 Replies View Related

Examples Of SQL Injections Through Addslashes()?

May 13, 2009

In PHP, I know that mysql_real_escape in much safer than using addslashes.However, I could not find an example of a situation where addslashes would let an SQL Injection happen.Can anyone give some examples?

View 2 Replies View Related

Installing Unit And Examples?

Apr 20, 2011

I am trying to learn PHPUnit. I use MacOS X and just installed PHPUnit using PEAR by doing this:

pear channel-discover pear.phpunit.de
pear install phpunit/PHPUnit

After installation, it's located in pear/share/pear/PHPUnit. It has Extensions and Framework folders.I tried creating the examples from the Pear PHPUnit tutorial, but in the example it says it requires PHPUnit.php and I don't see that file. Do I need to install anything else to make this work?Also, where should the example scripts be placed? guide me in setting up this PHPunit test and try it with one example?

View 1 Replies View Related

Looking For Examples To Remove Extension?

Mar 1, 2010

Let me explain, this isn't a apache question really (or at least I don't think so). I've noticed some sites that run on PHP but I notice they link to[URL].../example instead of /example.phpSo I checked if they were doing it through apache, so I did [URL]....example.php and a 404 error came up.Now I've tried using apache to remove the extension and was successful, but I noticed I was able to access the site as example.com/example.php and [URL]...e. If I accessed the site with the extension and all links refenced without the extension, the links would break.A good example would be www.last.fm. On the index page everything is last.fm/?variable=foo. Other pages such as Music is last.fm/music. It looks like those types of pages have some mod rewrite as certain links have last.fm/music/reference/to/somewhere.But were you to access last.fm/index.php?variable=foo, it would return a 404, likewise last.fm/music.php.So I'm wondering what methods are used to accomplish this, if anyone knows where I cn read more about it.

View 6 Replies View Related

Tutorial With Practical Examples?

Apr 12, 2010

can someone there help with php tutorial with practical, result of each code they write?am learner,as l learn, i want to see practical output of each code i learn, will be appreciate if someone help.

View 1 Replies View Related

Examples Of The Limitations With JavaScript?

Feb 20, 2009

I'm looking for problems I can generalize, recognize later (in design), and say "Hey, if I continue down this road I'm going to hit trouble. PHP + JS just weren't meant for this."If I'm using PHP+JS.. what can't I do? What shouldn't I attempt?

View 4 Replies View Related

Printing Code Examples

Aug 21, 2007

I am building a tutorial site, all is working apart from 1 thing.

If i type in some php code even basic stuff like

<?php echo date ('Y'); ?>

then when its submitted into the database the php gets stripped away i'm using the tinymce editor if that helps make it clear.

I need to be able to show code examples as my tutorials are for web design does anyone know a way of showing code.

I can disable the tinycme editor and type code right into the textfeild and use the html safe values like: &lt;?php echo date ('Y'); ?&gt;

but thats not a good solution as i want to use the tinymce editor as my members will be able to write some tutorials.

View 8 Replies View Related

Application Service Layer - Write API Method Interfaces?

Nov 4, 2010

How do people design their service layer interfaces? I'm programming a large web application (in PHP) and we're using MVC, and programming thin controllers e.g. (pseudo code follows)

public savePersonAction() {
$input = filter($_GET);
... input validation ...
$result = $this->_service->savePerson( ? );
... etc
}

Should savePerson in the service take an argument of the entire $input structure or context (in PHP, an associative array)?

E.g. this - public function savePerson(array $input) { or should one separate out all the input fields and provide a "hard" interface e.g.

public function savePerson($title, $firstName, $lastName, $dateOfBirth, ... etc.. for many more) {

View 2 Replies View Related

Find Really Good Code Examples?

Sep 4, 2010

I am a new web programmer and am always looking to improve my knowledge and skills. As such I have read countless times on stackoverflow that a good way to do this is to read other peoples code. This is all fine and well but where can i find some good examples of really well written code? Im thinking specifically php here since this is my main language of use and as its server side i can just look at the source?

View 2 Replies View Related

Doctrine Mapping Examples Using PHPDriver?

Sep 13, 2010

I am investigating Doctrine 2 for PHP and I am having trouble finding good resources for how to map using the PHPDriver. There is extensive documentation on using Annotations in comments for the Doctrine mappings, however, I would rather have my mapping definitions in PHP and NOT in comments (for obvious reasons).

I could use some examples mainly with association mapping. The documentation using Annotations doesn't really help me much. Using those I seem to be left guessing through trial and error on how to do it with the PHPDriver.

View 2 Replies View Related

Examples Of Websites Built Using Yii Framework

Mar 30, 2011

What are good examples of websites built using Yii Framework. I wonder if it is being used ready in a large scale.

View 2 Replies View Related

Html - Web Page Examples Look Like Before Mod Rewrite ?

Aug 8, 2010

I want to display all my tags on one web page for example,[url].... and then when some one .clicks on one of the tags I want to display all the posts related to that tag on another web page for example, [url].... how would I be able to do this since it really would not be a good idea to create a web page for each tag?

I will be creating an index.php page for the tags folder [url]....But how would I be able to display the posts related to that tag on another page for example,[url]....

View 3 Replies View Related

Examples Of Well Written Large PHP Projects

Sep 6, 2007

To improve my PHP I've decided to study the source code of a medium to large open source PHP application. Can anyone recommend any applications that they would consider prime examples of well written PHP? The sort of attributes I'm interested in are basically just good software engineering such as clean internals, being well designed, good use of abstraction and also perhaps being well tested (things where there is a lot of room for improvement in my code ).

View 1 Replies View Related

Html - Class For Creating Form Interfaces To Database Tables?

Aug 10, 2010

I often need to create html admin interfaces to administer data in tables. In other words, a page that lists all the records and lets you step through multiple pages of records, and perhaps sort or search them, along with the ability to add or delete a record, or update an existing one.

I do not like to use big frameworks that include dozens of files and force you to code in a particular way, but prefer to use good individual classes as I need them. But I've never found a neat way to make this kind of admin interface. I've been rolling-my-own with a combination of jquery, the jquery datatables extension, and my own PHP functions.

View 1 Replies View Related

ADVERTISEMENT