Discover the best of the web!
Learn more about Digg by taking the tour.
On PHP and Libraries
particletree.com — So much emphasis is placed on JavaScript libraries, but with PHP all of the attention is stolen by frameworks. While frameworks are nice, they do require quite a bit of learning and some major alterations to coding style — especially MVC frameworks. But sometimes it is nice to just have an aid, a simple helping function, instead of a core ...
- 501 diggs
- digg it
- lithite, on 10/12/2007, -2/+4good post.
I know that I have never used a framework on PHP, though I'm sure it could be helpful, I'm just too add to stick with it long enough to learn.
libraries have definitely saved my life a few times.- timdorr, on 10/12/2007, -0/+4An OK post, but I have to take issue with this statement: "On the surface, PEAR seems to be the ideal solution because it is a group of libraries that are all documented, maintained, and tested. However, it is quite intimidating and is slightly overkill."
I'm afraid I don't understand how documented, maintained, and tested set of PHP libraries is intimidating, but a documented, maintained, and tested Javascript library isn't. And overkill? A 72KB Javascript library isn't overkill? - laceration, on 10/12/2007, -2/+4I looked at a lot of frameworks and found them all bloated. Why should I contend with their learning curve, overhead and be locked into their system when I was already proficient in PHP. It's disappointing that php is developing an official framework. If you want that kind of structure why not program in C++ and mfc. Php is not about learning a big complex system, it's accessible and usable from day one when you start to learn it and is more about programming creativity. No less than the inventor of PHP makes similar points: http://toys.lerdorf.com/archives/38-The-no-framework-PHP-MVC-framework.html
MVC is way overhyped. The model is your db, view is html/css and control is php. Its that simple, it was probably never even worth mentioning. As for the neat separation the frameworks promise, it never quite happens in reality.
Over the years I have developed and adapted my own libraries. PHP is about developing your own style. - SuperSloth, on 10/12/2007, -0/+2@lacertaion
"model is your db, view is html/css and control is php"
This works for simple web apps like blogs, forums, and eve simple content systems, but it doesn't work very well at all once your data model is remotely complex. Simply put, Object models generally do not fit into a Relational model very well. When you find this to be the case for your project, you will go shopping for an ORM.
Alternately, you may find that your project has hundreds or thousands of views, and embedding the view code into PHP makes it impossible to tell what's going on. At this point, you will seek to abandon PHP as your core templating language because it simply will not do the job as well as a dedicated templating language, or begin to use URL rewriting.
Eventually, your project may grow big enough and complex enough that you need more control and code partitioning, or you find that your ORM and templat. At this point you should use higher end MVC frameworks, such as those often associated with J2EE.
At the lowest end of complexity is plain old HTML. Most Internet sites can use medium complexity solutions such as scripted/templated websites (PHP, ASP, Perl, Python) and store the content in a simple RDBMS (SQLite, MySQL). High end complexity web services typically use Oracle, J2EE, and Tomcat as well as Struts and other Java frameworks.
Now, I agree that MVC is currently a buzzword (not as bad as a year ago, however). The thing is, MVC is meant for much more involved development than most people need for standard websites that serve up static or mostly static content or that use pre-built forum, blog, or CMS software. It's like buying a pneumatic tool set and an air compressor to assemble IKEA furniture. Doesn't mean other people really need those tools. Just means you don't. - cherouvim, on 10/12/2007, -0/+1@SuperSloth: MVC is not a buzzword. It a real thing and has been around for 27 years now.
http://en.wikipedia.org/wiki/Model-view-controller
- timdorr, on 10/12/2007, -0/+4An OK post, but I have to take issue with this statement: "On the surface, PEAR seems to be the ideal solution because it is a group of libraries that are all documented, maintained, and tested. However, it is quite intimidating and is slightly overkill."
- noodlez, on 10/12/2007, -0/+2if javascript weren't so sandboxed and had the ability to make frameworks (it'd be a different language, then, though), i'm sure that the buzz would be about javascript frameworks, too.
i think that most developers have their own personal libraries in whatever languages they use, full of the functions they use the most (and they're most proud of), whether they use frameworks or not.- noodlez, on 10/12/2007, -0/+2gah, didn't finish my edit in time:
libraries are great, but they're a rung or two lower on the productivity ladder in comparison to frameworks. and thats why the focus is on them. - Haplo, on 10/12/2007, -1/+1client side language (JavaScript) server side language (PHP). You are missing something.
- noodlez, on 10/12/2007, -0/+1missing nothing, hence the "sandboxed" part of it. they're two languages with different uses. one's extent is libraries, the other's is frameworks.
my point was that if javascript had the ability to go as far as having a framework, we wouldn't hear about all the javascript libraries anymore. or if php couldn't do frameworks, we'd only hear about php libraries.
- noodlez, on 10/12/2007, -0/+2gah, didn't finish my edit in time:
- dante2010, on 10/12/2007, -1/+31When I was a young lad I used to code PHP at the library all the time. Now I just code it at home mostly, as I find it more comfortable there. I'm not dissing coding at libraries as you can get alot done there, since it's pretty quiet most of the time. I just prefer to code my PHP stuff at home now.
- nutcase, on 10/12/2007, -1/+3finally a dose of sanity
- Teaboy, on 10/12/2007, -0/+2Thanks, it's not often I read a comment and actually laugh :)
- theearache, on 10/12/2007, -2/+0I think using framework increases output and productivity. Takes a little bit a way from certain creative aspects, but the pros definitely outweigh the cons.
- cyberwiz01, on 10/12/2007, -0/+2The comment boxes on that site are pretty cool.
- spyraled, on 10/12/2007, -0/+3For PHP I've always just written my own libraries. Maybe it's because there was nothing out there or maybe it's because I have a better understanding of PHP than JavaScript.
However, now I have classes I've written to handle database connections, connections, creating "objects" out of information pulled from a table, image handling, form validation, file uploading, gui elements such as data grids, menus, hierarchal trees, etc etc etc.
They've really made creating new projects MUCH easier, although when I was developing them at first they took a while. - supernerd, on 10/12/2007, -0/+0There is a place for both in PHP. I use a framework, the zoopframework to be specific, when writing an application. Within that application for specific needs I use various libraries to accomplish a specific task.
The advantage of a framework is a general structure and consistency that any compilation of libraries couldn't match. - WetSplatter, on 10/12/2007, -1/+2The core reason to use framework is for the rapid development and deployment of applications, be it on the desktop or the web. Framework combines all of the commonly used functions into standardized library for use.
Coding throughout the framework usually remains the same so the entire development process is streamlined. You can make development even easier by making your own libraries to include with frameworks so your common functions are easily access able across all projects, such as a Data Access Layer (connecting to the database, performing functions).
Framework makes projects standardized. - sonofagunn, on 10/12/2007, -0/+2I'm in the camp of "libraries over frameworks." Frameworks are just a design pattern. If you have that design pattern in your head and follow it religiously, you have more flexibility *not* using a framework. The stuff that MVC frameworks do for you is really trivial stuff. I don't see the purpose unless you have a team of people and don't really trust them to all follow the design pattern and "in house" object oriented bases classes and libraries.
A nice set of base classes can be a framework. Doing them yourself gives you the ultimate in flexibility and is really the most trivial part (and perhaps the most important part) of developing a web application.
That's just my opinion though. Different strokes for different folks.- Robotsu, on 10/12/2007, -0/+2MVC frameworks are trivial? Have you used any of the Rails-like frameworks which are currently popular? Aside from traditional support objects, the scaffolding enables you to roll out custom database-backed applications in minutes. Whether you want to get locked in or not is completely understandable, but I wouldn't call them "
trivial". - sonofagunn, on 10/12/2007, -0/+1Yes, I'm saying that adding some CRUD methods to your objects is trivial. Adding some PHP forms to support CRUDding of those objects is also trivial. RoR can do it in a few seconds. It may take an hour or two to do it by hand.
Most projects last for months and require extensive customization over what RoR (or other frameworks) will generate "out of the box". What's an hour or two?
- Robotsu, on 10/12/2007, -0/+2MVC frameworks are trivial? Have you used any of the Rails-like frameworks which are currently popular? Aside from traditional support objects, the scaffolding enables you to roll out custom database-backed applications in minutes. Whether you want to get locked in or not is completely understandable, but I wouldn't call them "
- ReK42, on 10/12/2007, -0/+2http://www.woyano.com/view/213/Download-ezSQL-Database-Class-203
That database class has saved me so much time. - chapium, on 10/12/2007, -0/+3I've had the hardest time figuring out what code such as: $this -> foo = $bar; actually does. Can anyone here clarify?
- TenebrousX, on 10/12/2007, -0/+1$this is used in classes to reference variables in the class. The '->' means "use $foo in this class". $bar is what you want to set $foo to. When you make a new instance of class "class", you could write
$instance = new class();
then access functions or variables in $instance by writing
$instance->function();
or
$instance->variable;
- TenebrousX, on 10/12/2007, -0/+1$this is used in classes to reference variables in the class. The '->' means "use $foo in this class". $bar is what you want to set $foo to. When you make a new instance of class "class", you could write
- loconet, on 10/12/2007, -0/+1For large PHP projects, http://www.symfony-project.com/
- jkndrkn, on 10/12/2007, -0/+0PEAR provides decent database connection classes that work in PHP4 and PHP5. For input field validation, file upload handling, and user authentication/session handling I write up my own.
- strkr98, on 10/12/2007, -0/+0One of the biggest benefits I haven't seen mentioned regarding third party libraries/frameworks is that for the major ones, they've been tested on a large scale. PEAR is used in hundreds (if not thousands) of apps, so you can be fairly certain when using a PEAR module that there will be minimal bugs. While I also tend to write my own libraries to use, its not always worth the extra time it takes to test/debug them. And stress testing a new lib isn't something everyone can do in a test environment.
- nify, on 10/11/2007, -0/+0Cool! I swear i saw it on freshmeat or somewhere else.
Digg is coming to a city (and computer) near you! Check out all the details on our