Building a real object oriented framework in PHP, suggestions wanted?

Although Kohana reuses many common design patterns and concepts, there are some things that make Kohana stand out: Community, not company, driven. Kohana development is driven by a team of dedicated people that need a framework for fast, powerful solutions Strict PHP 5 OOP. Offers many benefits: visibility protection, automatic class loading, overloading, interfaces, abstracts, and singletons Extremely lightweight.

Kohana has no dependencies on PECL extensions or PEAR libraries. Large, monolithic libraries are avoided in favor of optimized solutions GET, POST, COOKIE, and SESSION arrays all work as expected. Kohana does not limit your access to global data, but offers filtering and XSS protection True auto-loading of classes.

True on-demand loading of classes, as they are requested in your application No namespace conflicts. All classes are suffixed to allow similar names between components, for a more coherent API Cascading resources offer unparalleled extensibility. Almost every part of Kohana can be overloaded or extended without editing core system files.

Modules allow multi-file plugins to be added to your application, transparently Library drivers and API consistency. Libraries can use different "drivers" to handle different external APIs transparently. For example, multiple session storage options are available (database, cookie, and native), but the same interface is used for all of them.

This allows new drivers to be developed for existing libraries, which keeps the API consistent and transparent Powerful event handler. Observer-style event handlers allow for extreme levels of customization potential Rapid development cycle. Rapid development results in faster response to user bugs and requests.

I would look at Kohana. It came out of CodeIgnitor, and loading Models etc is done just the way you proposed. Check out their core features, many of which relate directly to your question (I've highlighted those): How is Kohana Different?

Although Kohana reuses many common design patterns and concepts, there are some things that make Kohana stand out: Community, not company, driven. Kohana development is driven by a team of dedicated people that need a framework for fast, powerful solutions. Strict PHP 5 OOP.

Offers many benefits: visibility protection, automatic class loading, overloading, interfaces, abstracts, and singletons. Extremely lightweight. Kohana has no dependencies on PECL extensions or PEAR libraries.

Large, monolithic libraries are avoided in favor of optimized solutions. GET, POST, COOKIE, and SESSION arrays all work as expected. Kohana does not limit your access to global data, but offers filtering and XSS protection.

True auto-loading of classes. True on-demand loading of classes, as they are requested in your application. No namespace conflicts.

All classes are suffixed to allow similar names between components, for a more coherent API. Cascading resources offer unparalleled extensibility. Almost every part of Kohana can be overloaded or extended without editing core system files.

Modules allow multi-file plugins to be added to your application, transparently. Library drivers and API consistency. Libraries can use different "drivers" to handle different external APIs transparently.

For example, multiple session storage options are available (database, cookie, and native), but the same interface is used for all of them. This allows new drivers to be developed for existing libraries, which keeps the API consistent and transparent. Powerful event handler.

Observer-style event handlers allow for extreme levels of customization potential. Rapid development cycle. Rapid development results in faster response to user bugs and requests.

One thing I've noticed is that a framework is usually built for a specific purpose. Generic frameworks (like CodeIgniter) are good for smaller sites and getting things up and running quickly. However once you have specific things, which fall outside of the generic framework building your own does become a reality.

The only thing I would suggest is to be consistent. That is relentlessly consistent. If you decide to name things in camelCase then don't deviate from that.

Or if you decide to use the NounVerb convention of naming methods i.e. SpaceJump then don't switch to jumpSpace even if it 'sounds' better at the time. Choose how you'll accept parameters and be consistent on that.

Will you accept only parameters or associative arrays of parameters? Choose and stick with it. I would also not over-engineer before you've written anything.

The consistency thing will take you pretty far before you'll need to refactor... but I wouldn't be afraid to do that as well. (A unit test or two should ease those fears). Yup, there's usually no right or wrong way to do things as long as you're consistent.

Did I mention... Be Consistent!

A lot of experience is needed to build a technical framework (no offense) and there are already 1'000's of CMS/basic objects (session management, ORM, etc. ) framworks/libraries. Instead of wasting precious time (no offense again), you better have to: Evaluate and select the framework that better suits your needs (some have a really good OO architecture). Learn will using this good framework.

Build your own OO business/application framework. (This is where you can learn, differentiate and create value).

– Click Upvote Oct 2 '09 at 22:09 A framework with business logic only. Take stackoverflow: build/extend a framework to implement a "badge/reputation system" (for sure you will be successfull if you do it right and you will have fun). All the rules are "business" logic (it has value).

How you save data in a DB, cookie, etc. Leave it to the technical framework (it has no value). :) – Toto Oct 2 '09 at 22:28.

You can build your own but why not make use of the vast libraries included with frameworks available and if required extend their functionality. Why don't you take a look at the Zend framework. It's fairly quick to get started and includes a lot of useful libraries and classes as standard.It's good for personal projects if your just looking to gain more experience with OOP.

framework.zend.com.

I've learned PHP the procedural style and just in the last year have been getting myself familiar with classes, objects, namespaces, etc. I wanted to build a simple MVC framework to better understand object-oriented PHP. I know this is from 2009, but is the concept still relevant? Would this be a good way to begin a simple MVC to become more familiar with objects?

Or is this example too old and uses a bad design? Is it good design to have a single "base" class where you extend it with subclasses?

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions