Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

relationship between size of project and need to use PHP framework

Tags:

php

What size of PHP project do people think "i really need a framework for this"...

Take this code:

<?php
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = 'password';
$dbname = 'test';

$conn = mysql_connect($dbhost, $dbuser, $dbpass) 
        or die("Cannot connect to mysql server");
mysql_select_db($dbname) or die("Cannot select database");
$delete_item_id = mysql_real_escape_string($_POST['id']);
$result = mysql_query("delete from `timesheet` where id ='".$delete_item_id."'") 
          or die(mysql_error());
?>

This would take 5 minutes to write by hand in Notepad++, surely a framwork would be overkill for this script!

Or do people who use frameworks...always use frameworks?

like image 307
benhowdle89 Avatar asked Dec 01 '10 13:12

benhowdle89


People also ask

Why do we need to use PHP framework?

Using a PHP framework cuts down development time, because frameworks automate several tasks. With a framework, a PHP developer can automate common tasks like authentication, session management, caching and URL mapping.

How many frameworks are there in PHP?

Wikipedia lists 40 PHP frameworks, but some of those are better described as content management systems, and undoubtedly there are many more. Early PHP frameworks include PHPlib, Horde, and Pear.


2 Answers

I stand in a very different place than most people on this issue.

The size of the project is irrelevant. The size of the team and all future teams is what is important.

A framework, regardless of what you've been told, will slow down development if you are a quality programmer. What you gain from a framework are way more important than that. Firstly, you'll create more maintainable code. Secondly, you'll create more standardized code. Lastly, you'll create more segregated code.

All of these things only matter, with the possible exception of the first one, to teams.

If you are a solo dev, and you know what you are doing, you can spring up the core bits of frameworky doodads you need very quickly. You can maintain a personal library of classes and functions that you come back to all the time, and you can decide what you need for each project as you need it.

You are right, something small that only needs to take 5 min to make, should just take that 5 min to make. Take my silly little Genetic Algo Funny Image Generator at http://www.twitterandom.info/GAFunny/ which is little more than a couple database tables, some directories, and one page. But with a bunch of really hardcore classes to do all the GA work.

How would a framework have made that project easier or better? It wouldn't have. Yet it IS a reasonably complex project.

Turn the table. What if I were building that with a team and we needed to all work on it at the same time? What if the plan was for me to stop working on it a year from now and 10 other people would need to pick up where I left off?

Then a formal framework becomes vital. That is where using something standard, in this case something like smarty or symphony, would really make finding new programmers to work on it easier.

That is where a framework becomes a requirement. With a team. And the larger the team, and more often it turns over, the more important it becomes.

like image 85
DampeS8N Avatar answered Sep 28 '22 14:09

DampeS8N


You need a framework (no matter if existing or self-made) as soon as either of those is true:

  1. you want multiple programmers to work on one project
  2. you want to be easily able to modify/replace parts of your project later
  3. you want your project to be easily extendable
  4. you want new programmers to get into the code quickly
  5. you want to seperate logic, presentation and data from each other

Yes, short one-shot scripts don't need a framework, but as soon as it gets more complex you need one, even if you write one yourself (i recommend to use any existing framework though, as you can then hire people who already know it which reduces the effort to train them on your code)

like image 28
Morfildur Avatar answered Sep 28 '22 14:09

Morfildur