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 foundation. That being said, here are some of the classes out there that help me get through the day to day:

  • JSON-PHP - Because JSON is fun to work with when compared to XML.
  • In house database class - Highly modified since then.
  • Smarty - OK, this is kind of a framework, but it is standalone enough so that it doesn’t hijack your code completely.
  • In house validation class - check for valid email, address, etc.
  • LibMail - Every program sends mail.
  • In house logging - loosely based off of Logger and the native error_log.
  • A handful of less reusable code that handles authentication, files, xml, strings, and so on.

The arrangement of libraries above is quite lacking. The most obvious flaw is the lack of consistency. With that comes varying levels of documentation, stability, and a helpful development community. So when a new programmer is brought on the project, they will have to learn various information from various sources. Or even worse, when a new project is started, any code that is not object oriented will have to be rewritten or modified to accommodate the new conditions.

Two mainstream organizational solutions present themselves: frameworks and PEAR. While this may change over time, frameworks are currently not appealing to me because they control how you code, and once you begin with one you are locked in. 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. Or maybe PEAR is the de facto standard that is irreplaceable. Either way, it is interesting to explore additional options.

A few questions arise. Is there room for a PHP equivalent of Prototype.js? Not a clone, but a similar idea. A group of files that simplify development and are in a standalone format as seen with the files. Is there something already out there other than PEAR, or any highly recommended classes out there commonly used by most PHP developers? Or is this line of thought ridiculous because frameworks already solve all of these problems?

HTML Form Builder
Ryan Campbell

On PHP and Libraries by Ryan Campbell

This entry was posted 4 years ago and was filed under Notebooks.
Comments are currently closed.


  1. James Asher · 4 years ago

    I kind of like the new Zend Framework. Sure, you can use the MVC stuff if you want, but you certainly can use it for other stuff without it. Currently I use the Filter, DB, and Mail components. I’m looking into using some of their Auth and Registry components as well.

    If you’ve never taken a look, it’s worth a few minutes of your time.

  2. Keir Whitaker · 4 years ago

    I ended up doing something along these lines a year or so ago. I looked at PEAR and ZEND and found them both a bit too heavy for my needs so I wrote my own bunch of very loosely related classes that handle strings, files, db, images, paging etc that I now use in all my projects. These link into SMARTY for rendering and it all seems to hang together pretty well. The added bonus is I understand them and they are coded in a way I am comfortable with.

    In terms of third party classes I use a few including UniversalFeedCreator for RSS and PHPMailer, although this hasn’t been worked on for a while so I will definitely look at LibMail. It would be great to see classes generic enough that they could be slotted into your own PHP project without huge dependencies.

    Just out of curiosity do you plug your in house validation class into SMARTY, if so can you give any further details of your approach as I have almost got to the end of the road with SMARTY Validator.

  3. cosmo7 · 4 years ago

    You might like phpSprockets. It abstracts HTML generation and makes possible all sorts of things - XML factories, tag modifiers and so on. It integrates nicely with other tools too.

  4. Ryan Campbell · 4 years ago

    Keir, we don’t have validation and Smarty combined for all things on the site, but all dynamic forms do have them combined. The way we handle it is by building the fields and storing them in an associative array with type, name, value, etc. Then, if there is a post back, we add error to that associate array if the postback failed validation. In Smarty, we loop through the array and draw the fields. If the error value is not null, we draw the appropriate HTML for errors for that iteration.

    If you’re looking for direct integration (extending the class or something crazy like that) then no, we don’t take it that far yet.

  5. Scott · 4 years ago

    I suspect that many of us have written functions that are already reusable or could be made reusable with a little time. Personally most of the functions I’ve written are in ASP, since I was an ASP programmer for the past three years. Some of the functions I wrote were to duplicate functionality in PHP that doesn’t exist in ASP, but others are not present in PHP and could be converted to PHP with a little time.

    I’ve been unemployed for almost two weeks now and been working on my personal web site. One section of my web site is going to be for reusable functions in ASP and PHP. I’m just trying to decide how I’m going to go about it. Some functions are closely related so I feel I should put them together, while others are separate from anything else.

  6. Preston · 4 years ago

    I would love to use a PHP equivalent of Prototype for the same reasons i prefer Prototype over Dojo. But there must be a reason that php is so framework focused rather than library focused. Right?

    But speaking of frameworks. What is everyone’s opinion of CodeIgniter?

  7. digitarald · 4 years ago

    If you really want an enterprise Framework, which gives you free space about decisions which template engine and which database abstraction layer and you want to use. I use agavi, which fits perfect for ajax needs. Your actions serve the data, the views serve the template after the matched output_type. Download the sample app, give it a try. After diving into to code you will be agavi addicted :D

  8. Regin · 4 years ago

    Maybe you should take a look at: Then zend framework also seems to be aiming to provide a framework of classes beyond the MVC framework.

  9. Bramus! · 4 years ago

    Hi Ryan,

    instead of LibMail I have moved on to using PHPMailer and now recently to it’s successors SwiftMailer.

    Above that I also suggest on using a Profiler class, a Database Class which returns DB_Result instances (Iterator style), a navigation class (think fancy URLS without mod_rewrite), a universal upload class with extensive functionality (think write file straight to disk, or write file to disk after inserting some data in database), etc.

    wbr, B!

  10. Austin Schneider · 4 years ago

    PHP + Smarty + JQuery = Umm, what I use. Not a lot of people talk about JQuery and imo it’s the best javascript library. Smarty is great b/c it separates code from html, the same way css separates style from html(content).

  11. Kafuuin · 4 years ago

    I think sometimes using a framework will overload your page and your code. so why not keep it symple and use some cool libraries like: adodb, xajax, phpmailer and some pear stuff.

  12. Steve Francia · 4 years ago

    There 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. For instance, the Zoop Framework has a validation library, and also uses smarty for it’s layout, however Zoop has integrated the two providing seamless validation for both front end and back end. It does this using what Zoop calls guiControls, which appear to be based on .net’s webcontrols, but for php.

    Zoop also has integrated a mail library with smarty providing template based emailing as well as plain text emailing.

    This integration is why you would want to use a framework. More efficient usage of code.

    Zoop can be found at

  13. Jeff · 4 years ago

    JSON is built into PHP 5.2 now with json_decode() and json_encode() — extremely handy.

  14. Clayton · 4 years ago

    as others have already mentioned: Zend Framework. It is one of the most important things happening in the area of PHP right now. It is more cohesive. It is loosely coupled. It is(or will be) well documented. It doesn’t try to be everything for all things. It locks you in but only to a point since you can override the base classes. ZF has the elegance that PHP has needed for a very long time.

  15. Domester.NET · 4 years ago

    :) Thank you for a good libraries.

  16. Fred Snertz · 4 years ago

    I firmly disagree that PEAR is overkill. The PEAR DB libraries have served me well, especially the getRow, getOne, getCol and getAssoc functions - they’ve really taken a lot of the pain out of coding to the database. Likewise, while Smarty is the sexiest girl in the room, HTML_Template_ITX is the one you marry. With these under your belt, you can venture into classes like HTML_Quickform, Text_Captcha, and the like. I’m thrilled with how well PEAR has served us in a production environ.

  17. Andy · 4 years ago

    Has anyone checked out Picora? It seems pretty new, but I’ve used it on a small project and it’s one of the few frameworks I’ve used that really doesn’t get in the way. No libraries though, which I guess is the point.

    On PEAR though. Yikes. What a nightmare. The cross dependencies, and reliance on the core PEAR class / PEAR errors (which is a giant piece o crap) totally defeat the purpose of having libraries. The code quality is also pretty bad compared to the many other independent libraries. I never use it on anything that makes it to production EVER.

  18. Andy · 4 years ago

    Also in regards to the prototype.js comment Ryan, I don’t think there is room for quite the same thing in PHP because it isn’t prototype based, nor does it have open classes. The tight integration of iterators with pretty much every other part of the library is where prototype really shines, and you can’t do iterators with near the same ease. You could always extend ArrayObject to have each, find, reject, etc, but then you would have to pre define the callbacks you pass to the iterator, or use create_function. Yuck. A few years back I remember a debate on the PHP internals list about closures and how the core devs kept insisting they were just not useful for PHP. I still get significant mileage out of the language, but for me I knew then that long term that was the nail in the coffin for PHP.

  19. Marcus Bointon · 4 years ago

    For email, PHPMailer is getting old and has not been updated for ages (depite many users posting good patches for it). The new kid on the block is SwiftMailer ( which is very clean and PHP5-savvy.

  20. snk00sj · 4 years ago

    Best of all words = I’ve tried alot of frameworks, and this one is simply amazing.

  21. mark · 4 years ago

    Smarty? Uggg…that’s pretty heavy lifting.

  22. Karl · 4 years ago

    Hmn, Trackbacks don’t seem to be turned on … I wrote some stuff about the programmer and business reasons that people prefer frameworks when dealing with PHP.

  23. Chris Hartjes · 4 years ago

    I’ve used all sorts of frameworks and come to the realization that all they are really good for is organizing your output. I really like CakePHP, but I find it hard to use the components outside of building a web application. Where I work, we use Zend Framework and I like how there are components that you can use OUTSIDE of building a web app. I think people underestimate the power of doing that.

    Terry Chay brought me around to that line of thinking as well.

  24. wlvrn · 4 years ago

    For a fantastically simple and POWERFUL database class for PHP, check out ez_sql.

  25. Jeff · 4 years ago

    I, too, use a variant of ez_sql in all my projects (except I port/upgraded it to mysqli and added a few delicious functions like get_kvpair() which comes in amazingly handy for a query like SELECT id, name FROM users)

  26. free tv online · 4 years ago

    Everyone needs a hug.

  27. Duncan Gough · 4 years ago

    I was thinking much the same thing a while back, a PHP-DSL aimed squarely at building simple web apps would sell like hot cakes:

  28. Robin Millette · 4 years ago

    I used to code from scratch, using php savant, pear, feedcreator, simplepie and some home grown code, but now I’m moving towards Drupal. I guess you’d count that as a framework.

  29. Mark · 4 years ago

    I played with Cake a bit, but am taking a serious look at both CodeIgniter and ExpressionEngine as frameworks, along with their associated libraries.

  30. Michael McCorry · 4 years ago

    I’m not big on PHP frameworks. But when it comes to DB interfacing, I love Apart from that though, I’m happy with plain old php and my own library of useful functions that I’ve perfected and secured over time.

  31. ATC · 4 years ago

    which php and AJAX Library is the best…………..?

  32. Jonno Riekwel · 4 years ago

    Everyone needs a hug.

  33. Dennis · 4 years ago

    I’ve just started looking at CodeIgniter as well. I attempted Cake but it was so poorly documented. Seem CodeIgniter is much better documented. I’m still not even sure that’s exactly what I need. I’m of the same opinion that it would be nice to just have libraries to use. I use jquery and it is very helpful but it would be nice to have it all serverside instead.

  34. Mike Birch · 4 years ago

    For small basic sites with no database, I use my own code and classes.

    I use CakePHP for sites that need limited content management. I agree that it is poorly documented, but the google group is active and the gain in speed of development makes it worthwhile for me.

    For community sites and sites that need a complete CMS I use Drupal, which as Robin Millette says in these comments can be counted as a framework.

  35. Miguel Benevides · 4 years ago

    Interesting post. Judging by krugle stats on php source code indexed there, there are around 370k php functions and below 100k php classes… where/how do you guys get/store your best code snippets?

  36. yes · 4 years ago

    Everyone needs a hug.

  37. Rick Jolly · 4 years ago

    There seems to be some overlap as in what is considered a framework. Here is my take using examples: Frameworks

    • CodeIgniter
    • CakePHP
    • Zend Framework


    • Drupal
    • Joomla
    • XOOPS

    Template Engines

    • Smarty
    • Savant
    • My favorites: Html_Template_Flexy and PhpTal
  38. Jay · 4 years ago

    symfony is awsome! I have been using it for 3 months and I will never do a php project without it again.

  39. devmag · 4 years ago

    Have you looked at the the php content management system phpCMS? it is a quite unique and flexible solution, not just a template engine…unfortunately, the development seems to have stopped…

  40. Kingsley · 4 years ago

    I want to know how to develop a PHPmailer. Can anyone be of help?

  41. Kingsley · 4 years ago

    I want to know how to develop a PHPmailer. Can anyone be of help? please email me; Cheers!

  42. Motorcycle Guy · 4 years ago

    What’s so special about Json anyway. I think rest->xml is way easier to understand and way more universal, plus who wants to do heavy lifting in javascript anyway. Also I think the comments on this site are really awesome.

  43. mikee · 4 years ago

    Zebra PHP Component Framework - a lot of useful classes there.