Stack OverflowQuality PHP code/snippet repositories?
[+42] [10] Pekka
[2010-02-26 22:57:56]
[ php php5 code-snippets ]

Does anybody know any larger repositories of high-quality PHP classes and snippets? The only site I know is, and while I mean no disrespect to its owner/s, its design looks pretty outdated (already has for a looong time) and the "social control" in terms of people reviewing and commenting on code is weak: There are lots and lots of bad code there.

Does anybody know anything in this direction, preferably with Stack Overflow-like interaction possibilities - voting, wiki-style editing, community functions.....?

Update: Starting a bounty to see what's new, out of curiosity. I will award the bounty to any really new, good, and modern suggestion that fulfills at least a part of my requirements above.

(1) hahaha, i agree on the design and usability. - DarthVader
(12) There is nothing like StackOverflow - Jage
+1 from me, would be very beneficial to have a high-quality PHP code repository. - Alix Axel
Someone should just write one. I've been toying with the idea of a snippet hub for a while. Best solutions for common problems. You might even go as far as to make it multi-language, so common solutions can be ported. - theazureshadow
I realized I don't know anything like that for snippets. There are good component libraries, frameworks like ZF, ezComponents, etc. but they are too big. There's PEAR but no social aspect. There are PHP manual comments - which sometimes contain very useful code, but you never know. But not something like StackOverflow. An idea for a startup? :) - StasM
(3) Since you are looking for "independent" collections, if there were such a resource, most possibly someone here should already have known it. I hardly remember using a snippet without fixing it first. And with the horrible quality level of PHP snippets (and even complete libs/apps) in general, one should set very strict rules upon such a website, ZF level or higher. If you know or think to start one, ping me. - Halil Özgür
(3) doesnt classify as an answer because the latest addition was 2006, but Zend has a kind of official code gallery at You can even interface with it from Zend Studio. BTW, had a facelift since you wrote this. - Gordon
@Gordon thanks for the Zend hint, it's a shame this wasn't continued! Something supported / run by Zend would be the place for a quality repository. Re the facelift, thanks for pointing it out! I'm thinking what happened is, "We bought a template from during happy hour, and slapped it on our existing HTML, being very careful not to break any ads." :) - Pekka
(4) @Pekka well, the place is PEAR or PEAR2. These are official. The problem with snippets is: they are mostly uninteresting. Given that PHP already has a function for almost every general purpose, snippets can only be special cases. Most of the time, too special to be reusable. If anything, they are helpful to see how someone solved an issue. But the instant where that issue is non-trivial, you are leaving snippet-land. And that's when you are back at PEAR. I dont see why I would need a social element for PEAR though. If you want to improve their code, become a contributor. It's FOSS! - Gordon
@Gordon good points, good points! Although what I'm imagining goes a bit beyond snippets - well-defined classes to solve specific problems. Kind of like PHPClasses, but "in gut" :) But I can see I have to look at PEAR/PEAR2. Cheers. - Pekka
@Pekka on PHPClasses: what you suppose to be bought from templatemonster was in fact a result of a $2.500 competition :) I too feel the need for a "real" class repository though, preferably following ZF naming and other rules, for ease of use, inclusion and inspection. In fact, it's not that hard. The hard part is making people work together. Most of the code in frameworks are just duplicate. - Halil Özgür
@battal yeah, that was a bit mean :) But the tons of ads make it look like crap. Re making people work together - that's where a social component like on SO might come in, if somebody would manage to get it off the ground. - Pekka
[+15] [2010-02-26 23:22:17] Tchalvak [ACCEPTED] [1], for living code in repositories. After I started using git, I see code just in zipped files for download on the web as dead code and stuff in repositories as live code (more potential). Mainly because live code will have a development history with it, and dead code won't.

In addition, github allows you to easily see how often (if at all) a snippet has been forked, which is usually a useful indicator of quality.

Edit: Just to make that bounty a little more warranted, let me expand on this answer:

Pros of github, and live code repositories:

  • You can get in contact with the originator of a snippet.
  • You can get in contact with whoever *else*most recently made commits to a clone of the snippet.
  • You can (if you're lucky) actually code collaboratively, with people who actually made the snippets.
  • You can see how recently code was edited, which ties into how modern/up to date the code is.


  • Git has a huge learning curve (though tortoisegit [2] for windows might help with that).

More Pros:

  • Git is an amazing tool once you do get to know it.
  • Even if you don't use git, you can still see changes to the code via commits.

If you're not into learning git, your next best choice is probably going to be mercurial. There are certainly similar sites out there for mercurial. Bitbucket might be a good start. Beyond bitbucket, this question has suggestions for mercurial repository sharing/hosting:

Hosted bug tracking system with mercurial repositories (Summary of options & request for opinions) [3]

TL;DR: Code repositories trump code snapshots every day.


I wouldn't see the number of forks as an indicator for quality. But still, yes, I hate it if people force me to download and extract a zip in order to look at their code instead of hosting it on github. - NikiC
(5) I have found some real jewels in the code published on github. It's often a higher caliber programmer that uses git than other sites. - Xeoncross
Git hub is awesome. - Jessedc
I don't want to dispute the awesomeness, but it's just a DVCS hosting service and not very PHP specific. Many high quality PHP frameworks and applications are developed on github, yet it seems not the best source for individual and categorized php classes/libraries. It's a search only interface.… - mario
A shortcut to php on github - Elvan
[+10] [2010-11-04 03:53:50] ts.

There are some (in order of subjectively percieved coolness): - recently i found some pearls there, like phplinq or phpexcel ; there are ratings, stats and all that social stuff ;) with for little snippets, no ratings (but you can look at followers number) - no ratings - also with ratings and community (community orientet de facto), aggregates rather than hosts and - many dead projects, no ratings - with user recommendations - terrible as always, even after retouch of interface, but you have rankings (you can see "popular" snippets)

+1 for pointing out that when people on github have really tiny snippets of code they just use in the place of a full repository. - Tchalvak
I had forgotten about gists due to almost always using repos even for the small stuff myself (e.g. :p ) - Tchalvak
[+7] [2010-02-26 23:10:53] Byron Whitlock

I always look to the Zend Framework, [1] and the Zend Extensions [2]. They are usually very high quality.


(4) @Byron cheers, it's true, the ZF and associated libraries are very good stuff usually. Still, I am looking for an "independent" collection of well-written scripts and classes, some of which can have external dependencies but the collection as a whole should not be focused on one specific framework, no matter how good it is. - Pekka
[+7] [2010-02-26 23:13:46] Pascal MARTIN

First of all, you might want to consider two different kind of repositories :

  • Those which host codes / plugins / modules for specific applications and/or Frameworks
  • And those which host either generalistic portions of code or generalistic libraries.

In the second category, the first idea that comes to mind would be [1] -- but there is a lot of old code, many less-than-well documented libraries, lots of not-maintained stuff, ... Which pretty much means you'll have to go through a lot of stuff and eliminate the bad libraries yourself :-(

Two possible solutions might become interesting -- and they are quite recent :

I've never used those -- but it seems like some kind of repositories anyone can upload packages to ; and those packages can then be installed using the standard PEAR installer.

There doesn't seem to be any kind of voting / reputation / whatever system associated with those, though :-( But it might be interesting to suggest that as a possible improvement ;-)

So, not a real / great answer to your question, actually : there are components and stuff out there -- but the best way to know if something is great is to either test and/or review... And some stuff just lack documentation :-(

In the first category, things might be a bit easier : for lots of frameworks / applications, there are repositories of contributed modules or classes.

For instance, for Zend Framework, this could be interesting : ZF snippets [4] (not that much life there either, though...) ; but note that official components of the framework are generally much more useful/better.
And that is probably true for many frameworks out there...

Another example would be Drupal and it's repository of modules [5] -- and, there, you have some sorting by usage possibility, which is a bit of an indication of the quality (generally speaking) of those modules.


Pearhub is a great addition, but from what I've heard it is literally a few weeks old, so I doubt it has had time to really become rock solid. - Tchalvak
Pearhub and Pearfarm are indeed really not old -- I had never heard of them before the beginning of this year ;; I saved pearhub to my bookmarks on january 12th ; and judging from other people who bookmarked it on delicious, it's only a few days older : first bookmarks are from january 7th. - Pascal MARTIN
(2) Cheers Pascal, it's a good overview on what's there. pearfarm and pearhub look very interesting but I f*ing hate PEAR. A catalogue-like collection for anything - "I need a OCR library for PHP, I need a function to find the dominant colour in an image, I need a library to convert hex-RGB-LAB colours", stuff like that, is what I am looking for, and there doesn't seem to be a "Stack Overflow of PHP snippets" around. I have that idea back in my mind to start something in this direction... Maybe later this year. Maybe I'll open a question to test the waters to that respect. - Pekka
@Pekka : I really like the PEAR distribution system mecanism (it deals with versions, repositories, dependancies, ...) ;;; but I have to admit I don't really like : to much bad code and old/unmaintained components, there... ;;; Let us know if you dig deeper into your idea ;-) - Pascal MARTIN
[+4] [2010-11-02 09:12:03] Gerry [1], allows people to post a great snippet and others to then improve on it. You can also vote on the improvements. Really fantastic site for beautiful code. [ More info about the site [2]]

Most popular PHP snippets on RefactorMyCode: [ Link [3]]


(2) @Col Which two and what made them shit? The idea of the site is take a look at somebody's snippet and make it better. It's the platform I'm suggesting, not necessarily the "Two randomly picked snippets" that you looked at. - Gerry
Look. There are no php professionals who have spare time to hang around these platforms. They are busy, dude. Busy with real job. Only lamers would "review" your code, making it even worst. - Col. Shrapnel
(3) sigh, the irony, it hurts - Gerry
[+3] [2010-11-01 20:06:40] Mike C [1], but it's still in its infancy. As opposed to classes it's centered around functions.

The difference between it and other repositories is that you can run the code right on the server and see the results.


[+2] [2010-11-04 14:10:24] mario

Let me name three links to make this faux answer eligible.

  • PHP Code Exchange is pretty old, and sufferes from outdated code alike. It's clearly to avoid since there is still PHP3 code ($HTTP_GET_VARS) in it.

  • PEARHub is an independent PEAR repository and shows quite well that it isn't all bad. PEAR in general failed because of inherent complexity. In particular the distributed nature of PEAR repositories (and the difficulty to set them up) doesn't help. It would be an useful ecosystem for PHP if there was a centralised registry. And less bloat.

I also want to harp on the meta topic here. While the question is obviously about an existing and big archive of classes, it might also be a good idea to look out for smaller ones. Also because it makes little sense to dump new and quality code into sites like phpclasses. OTOH it's too frequently overkill to start a project on sourceforge, or even DVCS sites like github or google code. That's IMO the main reason we don't have a coherent or contemporary PHP class repository.

And because this question will surely inspire some SO fella to create something better, finally, let's also term the required attributes. Just opening another upload site isn't going to cut it. The quality miss has technical reasons with social causes.

  • Subscribe-Or-Fuck-Off: that's the main reason we have no big alternative. Aspiring projects shoot themselves in the foot if accounts are preferenced over contributions. One Stackoverflow feature that's imperative to follow for anything to succeed are: optional user accounts.
  • Voting: While important, voting alone doesn't help quality assurance. Or more precisely it's insufficient to have a single rating. Usefulness, security, nice API, documentation, and activity must have separate ratings.
  • Systematic code analysis: We have all the code analysis tools: PMD, PHP_CodeSniffer, PHP_CompatInfo, etc. They just need to be integretated in a PHP class hosting site. Instant quality raise.
  • OpenSearch and CC content.

[+1] [2010-11-08 11:24:29] Tmas

This answer may not be exactly what you're looking for, but try it out. It's got ratings and difficulty levels, but not very many snippets.

(1) @user I think you forgot the link :) - Pekka
I just edited it, but it isn't showing up... - Tmas
(2) Anyway, the link was You may also want to try out - Tmas
[+1] [2010-02-26 23:29:53] dlib

I think your best bet is Google Code and Github repositories, or any project specific repositories. That's how usually find relevant PHP code. Even just browsing them can be fun, there's a lot of nice stuff but it's hard to find.

Nonetheless, lack of documentation is pretty common.

[0] [2010-02-27 00:57:44] mehaase

In addition to Zend Framework (mentioned by Byron), also look at EzComponents [1].