Blog

PHP – No Container libraries?

Posted by:

Most compiled languages that I have used have some kind of container implementation, Lists, Maps, Trees, Stacks and all their many variations. PHP has arrays and the SPL.

This post is more of a question than anything else, are there disadvantages that I can’t see to having a standard container library for PHP? One problem that I can see is that containers built in user code will definitely be slower than a native implementation.

Am I overlooking something that already exists? Google fails me!

11


About the Author

Discussion

  1. Antony Dovgal  December 2, 2007

    AFAIK Etienne (http://www.colder.ch) is already working on reincarnation of PECL/adt (see http://cvs.php.net/viewvc.cgi/pecl/adt/), which is to be included into SPL.
    I don't know what are his plans or estimations, feel free to contact him (and give a hand).

  2. Matthew Weier O'Phinney  December 2, 2007

    While not exactly what you may be looking for, SPL's ArrayObject offers many features that allow you to work with lists, maps, and stacks easily in an OOP fashion as well as in an array-like fashion.

  3. Jon Gilkison  December 3, 2007

    I don't mean to sound blunt, but PHP isn't Java, so the need for such an extensive list of containers speaks of a misunderstanding of the best way of doing things in PHP. In PHP you are servicing a request, unlike Java where you have a stateful app server sitting there, pre-compiled and ready to rock and roll. Despite all the layers of abstraction that frameworks want to put on top of it, PHP's most basic purpose is servicing a single request and I'm of the fundamental belief that your code should echo that, meaning it should be fit and trim and very narrowly focused in its purpose – if that makes sense.

    The array in PHP is a map, despite its name, and you can treat it like a stack with array_pop/push/etc. Trees can be emulated with recursive population of the array.

  4. Donald Organ  December 3, 2007

    PHP is not a compiled language…..its a script language.

  5. Jon Gilkison  December 3, 2007

    That's what I said, Donald.

  6. Doug Hill  December 3, 2007

    Jon:
    Yeah, I'm aware of that :) "Program into your language not in it." — Steve McConnell. I was more curious than anything.

    Donald:
    Uh huh, I said that "compiled" languages that I've used had container libraries… not that PHP was a compiled language.

    Doug

  7. Donald Organ  December 3, 2007

    Then why are you compairing PHP to a compiled language, or why do you want it to?

  8. Doug Hill  December 3, 2007

    I'm not comparing them, I was curious if any existed, when I searched I didn't find any, PECL/adt was pointed out to me in one of the comments here.

    I can see some disadvantages, in user code it would be bloat. In a native extension it might be nice, who knows, I was just wondering what was out there.

    Thanks everybody for the input. I was looking for opinions and found strong ones!

  9. Adam  January 9, 2008

    Very nice! Kudos for the post.

  10. Marcelo Gornstein  February 18, 2011

    You might want to try Ding, which aims to bring some of the features of the Java world into php, like JSR annotations, IoC, DI, and AOP with performance in mind.

    Regards,

Add a Comment

  1. PHPDeveloper.org  December 3, 2007