Are frameworks really necessary in PHP?
What are the advantages and disadvantages of using one?
Are frameworks really necessary in PHP?
What are the advantages and disadvantages of using one?
No. But they are nice.
Pros: Saves time not having to rebuild the code yourself. Use the myriad of features, functions, and data structures someone else built that apply to your project.
Cons: Not having built the code yourself could be a loss at a better level of understanding on the foundation of which your project operates.
Web application frameworks are only as good as your experience with them.
Every framework has a learning curve, until you overcome that curve, you'll probably end up doing things so ass backwards that you negate all of the benefits of using a framework. Your application will be needlessly slow to develop, the code will be difficult to follow and the whole thing will break when a new version of the framework is released. I would recommend against attempting to use an unfamiliar framework (or any unfamiliar technology) for projects with a tight deadline.
How does one get better at utilizing frameworks?
You'll have to build a handful of god awful applications and iterate. Eventually you'll figure out the quirks, and using a framework will allow you shorter development time and better organized code.
Should you use a PHP framework?
Everyone who codes enough PHP eventually uses a framework. The question is, will you use your own framework or one developed by a third party? In my experience, you'll likely never develop your own framework which will match the robustness and quality of a third party framework. That said, developing your own framework seems to be a right of passage in the PHP community, so, don't let me discourage you from writing your own database abstraction class.
Here is a helpful graph:
According to Rasmus Lerdorf, you don't need any additional framework, as PHP is itself a framework. http://toys.lerdorf.com/archives/38-The-no-framework-PHP-MVC-framework.html
Well, it really depends on the size of your project. A homepage with no database and no more than 10 pages, a framework is going to be too much, mainly because framewroks always need a lot of configuration and customization in most cases, to fit specific needs. And in some situations they could be a little slower than several pages included in a file (think about all the framework needs to load to use its features.).
Now, if you are planning a mid/big size site, with database interactions, webservices, etc etc, you will need a framework to help you interact with different technologies and organize your code in a way that when things break, you'll have the habilitie to quickly detect and repair it. Also if you think about clients, they are always changing their mind about software, so if the client needs to modify or add a new feature you should not have to go trough all your code and think about how do i plug this new feature in all this sphagetti.
There are lots of others pros and cons, but these are the ones first crossed my mind.
Edit: I use symfony framework in daily bases and also done work with php for the university (i had some courses about web development that doesn't allowed to use any framework), so most of this comes from that experience.
You're kidding right?
Necessity depends on use. Computers aren't necessary to mankind, neither cars, etc.
As to advantages/disadvantages, to each it's own!
I'd like to show some example code off my own framework:
class Product extends DatabaseRow {
public $name='';
public $price=0.0;
public $images=array();
public $description='';
public table(){
return 'products';
}
}
$p=new Product();
$p->name='Bread';
$p->price=0.5;
$p->images=array('loaf1.jpg','bakery.jpg');
$p->description='Our premium diet bread.';
$p->save();
See what I did there? That class serves as a model for a shop. What's so special other than OO? If the table, or any column doesn't exist, it is created dynamically. 0 install scripts. Of course, this is a specific feature in my framework. But you get the idea.
$p=new Product($the_id); $p->load();
The load()
is to the a row merge as opposed to overwriting the whole row.
Commented
Apr 6, 2011 at 14:32
Not all applications require a framework, but most consequential ones do.
The advantages are:
The disadvantages are:
All in all, it's better to use one.