Looking for some advice. I’ve worked in procedural php for a while now, and have recently been on a 2-day PHP OOP course and learnt about classes, objects, inheritance etc, although it’s a lot to take in!..
Now at the same time we also talked about MVC and Frameworks ie Zend, Smarty etc.
Now my question is this; I obviously I want to start building my new upcoming projects in OOP, and need to become familiar with it.
But to do this would you suggest in a couple of upcoming projects (A business directory & CMS):
Writing your own MVC Framework?
Using one already in existance ie Zend?
What I’m thinking is writing my own Framework for now, until I become familiar with OOP and then look into using an existing Framework in future projects after this? Would you suggest that?
Also does anyone have any good video tutorials they have found online for building their own MVC Framework? Or any beginners guides online that are very basic for starting a framework.
I’m more “developer” than “programmer” so you can take my $0.02 with a grain of salt if you like. I do OOP design when I can (often at work we use WordPress, which is all a simple site really needs), but almost always use a CMS or Framework. I hate gluing libraries together and I just simply do not have enough time to hand code everything over and over.
Writing your own framework would be great practice, but from a practical standpoint (which is where I try to stand, always, lol), I can’t see much benefit. After all, a decent framework has hundreds of hours invested into it. Aren’t those hundreds of hours you would spend investing in building your own Framework better spent getting projects done, signed off, billed and collected upon?
Another thing I consider is if my client moves on. If it is a widely used framework they can find a developer that can pick it up and support it no problem.
I can’t count how many times a client comes to us asking us to pick up their shoddy custom program job and want us to extend it / fix it. A job that might take 4 hours suddenly takes 10 hours because we have to invest in learning how the framework works.
Two answers, which you select is entirely up to you:
Yes build your own
No use an existing framework like Zend
Building your own will teach you a lot, about architecture, design and more. You learn through osmosis, which is time consuming but effective and not dry and boring.
Building off someone else framework will teach you a lot. Through forced best practices and community effort and feedback you read in forums.
OOP and patterns are not easy to master, they take years. If you build your own framework using what you understand of OOP in the last two days, you will likley result in much criticism from other developers who may use your framework. You will get dependencies wrong and seperation of concerns, like what exactly goes in the model and can or should or could go int the controller.
You implementation of a front controller will likely have functionality that best be implemented in a supporting class like request or response.
Either way is effective at learning OOP. One may or may not be faster at teaching you than the other, really it’s subjective.
I have been building my own because simply put – I’m stubborn. Of course its my own little side project since I have nothing better to do in my off time (seems like the case for many of use,lol). Anyway, at work I use Drupal and a home grown contraption based on C and Oracle. When doing projects for friends, family and myself I use my own framework. Perhaps one day freelance, just not ready to take that plunge yet considering the job I have already pays the bills (and bars) fairly well, lol. Although mine began as soly a framwork and has emerged in a cross-breed between Drupal and Code Ignitor or CakePHP, its more a content management framework (like Drupal but OO) than anything. Many concepts I even “borrowed” from Drupal – Nodes, Fields, Views, Taxonomy, etc.
It’s a typical rite of passage for a PHP developer to write their own at some point… generally followed by the realisation that you might as well use the one’s that exist already. It’s still worth doing because you learn a lot in the process.
Building your own framework is a brilliant way to learn OOP styles (if you do it in such a way) and also means you get a framework that does what you need, not a monster that does what EVERYONE MIGHT need.
I went down the custom route myself, and havent’ looked back
Build one if you have time for your own applications, but if you are doing something for a client used a pre-built one. You will pull your hair out adding stuff for clients.
“Stuff for client” ? Really ? In an (H)MVC framework !
Where exactly would you put it there ? Or did you mean CMS ?
Anyway, about the topic : if you are just starting to learn basics for OOP,
then making a framework will be a bit too early.
It’s not that you cannot do it, but about 3 month after you finishing it,
you will have to burn all evidence and kill anyone who saw it.
I would suggest to do study a bit more OOP. Maybe skip through “Ajax in action” book.
Learn what the “Law of Demeter” is , and what are SOLID principles.
Some understanding of unit-testing and TDD wouldn’t hurt either.
( search in youtube “clean code talks” - you might find it interesting )
Its always better to stick with a proper framework with active community support that is available now. Because as time goes, you need to concentrate more on framework issues than your project features.
Okay, this is an interesting diascussion and while it is a little old now I wanted to have my say.
I have done both. Single-handedly built a framework and used it to power a custom CMS. This was good fun and a great way to learn OOP in PHP. I had a good understanding of OOP from other languages and study.
Currently I am using a framework - CodeIgniter is my framework of choice right now and I think it’s great; light weight and powerful with an excellent community.
So, my recommendation would be to use a good framework at this stage as this will give you lots of scope for learning the best way to do it. In addition keep an eye on the forums ewven when you don’t have a question you may find an interesting topic that will increase your understanding.