Slashdot Mirror


Elegant PHP Architectures?

akweboa164 asks: "I work as a lone developer creating small to medium scale PHP/MySQL websites for different clients. I have been doing this for about two years now, and have tried different things as far as website layout/architecture goes. With sites that use the fusebox architecture, front controller (thanks J2EE), N-tier, to having a simple 'include(config.php);' line at the top of every file, I am left with the feeling that all of the sites I have created are 50% elegance, and 50% nasty kludge. I am left with a sinking feeling because I know that they could be better, but I lack to expertise and experience to make them that way. I am looking for overall architecture that is open and fits within the constraints of PHP (ie. relying little on OO) and separates logic, makes updates easy, etc. I wanted to ask Slashdot's crowd of web developers what their most elegant code layout/design web solutions were, and what advice would you dish out to new developers, as well as seasoned professionals."

1 of 118 comments (clear)

  1. Re:Relying little on OO...? by ptaff · · Score: 4, Interesting
    The model is still incomplete.

    PHP5 promises great features, but PHP4 still lacks lots of OO concepts.

    • No private/protected/public
    • No static class attributes
    • No abstract classes nor interfaces
    • No function overloading
    • Still experimental aggregation/composition


    You can do OO-like stuff without the points above but at the expense of no encapsulation and ugly hacks.

    Some elegant constructs are hard to achieve in PHP, a statement like this (in java) would have to be dereferenced one by one by hand:
    object.person.bart_simpson.say("Bite Me!");
    Somebody who has already done some OOP would be able to find workarounds but PHP would not be a good way for a newbie to learn OOP.