Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

Are frameworks really necessary in PHP?

What are the advantages and disadvantages of using one?

share|improve this question

closed as too broad by Konrad Morawski, MichaelT, user16764, GlenH7, Bart van Ingen Schenau Mar 26 at 14:34

There are either too many possible answers, or good answers would be too long for this format. Please add details to narrow the answer set or to isolate an issue that can be answered in a few paragraphs.If this question can be reworded to fit the rules in the help center, please edit the question.

1  
thankx for editing it. ChrisF –  Tayyab Gulsher Vohra Apr 6 '11 at 11:46
    
please also mention the name of the php frameworks and there advantage and disadvantage. –  Tayyab Gulsher Vohra Apr 6 '11 at 11:57
4  
This question is pretty much valid for any programming language. –  Htbaa Apr 6 '11 at 12:09
1  
Recently ran across this SO post that looks rather insightful regarding the use of PHP without a framework stackoverflow.com/questions/3655145/… –  XHR Apr 6 '11 at 12:58
1  
if you are just started using PHP, you should play around with PHP more first before deciding any framework. It's fun :) , or maybe trying to create your own framework. –  Phelios Apr 7 '11 at 2:32
add comment

6 Answers

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.

share|improve this answer
    
but the problem is that day by day there are alots of frameworks i dont know which one to use –  Tayyab Gulsher Vohra Apr 6 '11 at 11:58
4  
@Tayyab You gotta use `em all! –  Arnis L. Apr 6 '11 at 12:12
1  
Choosing a framework is for you to decide, based on the needs of your application and your coding style. Also ask yourself, do you need a framework to roll your own app, or a CMS (Joomla, Drupal, etc)? –  Darren Newton Apr 6 '11 at 12:15
    
You have to be careful about "unknown unknowns". If you don't use a framework, the risk of forgetting or not knowing about some stuff that frameworks solve for you is large. For example, are you correctly dealing with CSRF attack prevention? Your app will work without such a prevention, but it will be easily hacked. Choosing a major framework (any of them) means you benefit from all the stuff that web apps have to concern themselves with, even if you haven't learned about it yet. –  Joeri Sebrechts Mar 13 '13 at 11:02
add comment

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:

enter image description here

share|improve this answer
add comment

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

share|improve this answer
    
well guys i am a biginner and i am trying to write code i am new to it and i want to be a core developer of php so please guys suggest me –  Tayyab Gulsher Vohra Apr 6 '11 at 13:12
1  
That article is from 2006, and is embarrassingly out of date. –  Jonathan Rich Mar 13 '13 at 13:53
add comment

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.

share|improve this answer
    
well i am a beginner in php and have not develop any thing big yet and i am to confused what to use and which i should go for really i am totally blank –  Tayyab Gulsher Vohra Apr 6 '11 at 12:14
    
First step would be not use them, learn the technologies and how they work (php , framework, js, css, etc), then once you have understood the basis of php programming, then use a framework like Zend or Symfony or CakePHP to learn how to boost your applications –  guiman Apr 6 '11 at 12:16
add comment

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.

share|improve this answer
    
i want to tell u some thing guys actually i am using 2 frameworks one is codeigniter and the other is yii and i want to become a core developer but my OOP Concepts are not so good the truth is that . –  Tayyab Gulsher Vohra Apr 6 '11 at 13:19
    
How do you differentiate between an 'UPDATE' and 'INSERT' statement in the $p->save() method ? –  Srisa Apr 6 '11 at 13:42
    
@Srisa - I didn't set an ID. To do an UPDATE, I need: $p=new Product($the_id); $p->load(); The load() is to the a row merge as opposed to overwriting the whole row. –  Christian Apr 6 '11 at 14:32
add comment

Not all applications require a framework, but most consequential ones do.

The advantages are:

  • Don't repeat yourself - Any new application is will have functionality in common with many existing applications. It makes sense to avoid repeating yourself. A framework bundles functionality you'll need for most applications. You'll consequently save time (and money).
  • Don't drudge yourself - Software development in general can be quite grindingly painful. It makes sense to automate the mundane stuff. A framework takes care of the plumbing, so you can focus on being profoundly creative. You'll consequently save effort (and money).

The disadvantages are:

  • Our way or no way - You may have to follow the framework's rigid conventions, which might contravene your dogmatic beliefs about how things should be done (and consequently enrage you).
  • Acquired framework syndrome - You may become too dependent on frameworks to get even the simplest things done. You'll forget how to route requests, access databases, map objects to database queries, etc since the framework holds your hand through all that.

All in all, it's better to use one.

share|improve this answer
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.