On Saturday 27 December 2008 6:57:18 pm Murray wrote:
> I'm interested in this topic as well. I'm starting out on a reasonably
> large web application, and I'm wondering at the best approach in PHP,
> particularly since it's been some years since I worked with PHP on a daily
> basis (the last 5 years have been purely C#).
>
> There's some dev community bias against using frameworks, isn't there? On
> one hand I'd love to take an approach that would make my end goal easier
> (thanks for pointing out Code Igniter, I'll look into it further), but on
> the other hand I'd rather avoid choices that 'tainted' (perhaps not the
> right word, but the best I could think of) the overall acceptance of the
> application once it's ready for release.
>
> So, currently I'm wondering about things like, 'Do I make an app that is a
> distinct page-per-function, or do I make an app that uses a monolithic
> index.php (similar to Wordpress?) and dynamically presents
> *everything*based on querystring values.'
>
> M is for Murray

There are exactly 47 architectural patterns, not a single more or less.  And 
if you believe that, I have a bridge you may be interested in. :-)

Seriously though, you'll probably find an existing implementation of any 
architectural pattern in PHP, including the ones that have absolutely no 
business being implemented in PHP.  (I include MVC in that, actually[1].)

If you really want to know about OO patterns, pick up the Gang-of-Four book[2] 
and spend some time wrapping your head around it.  (Warning: It is written 
mostly for a C++ audience, but it's still understandable.)  Then ignore those 
patterns that require more setup effort on each execution than they take to 
run, as those are ill-suited to PHP's shared-nothing architecture.  An active 
Observer, for instance, really sucks in a web app but a passive observer can 
do great things.

Then, get over your OO biases. :-)  PHP can do functions just as well as OO, 
and because of the setup costs in "proper" OO doing things with functions can 
often be much faster and require less mental overhead than building out a full 
OO setup.  There are plenty of major projects (PHP and otherwise) that use 
virtually no OO and still manage to kick ass.  (Drupal comes to mind, and the 
Linux kernel itself is all C code, which doesn't have syntactic OO.)  Don't 
assume that architecture just means OO.

Page-per-action vs. a front controller (the index.php to rule them all, 
usually with mod_rewrite) depends on your app and how you want to extend it.  
I personally far prefer a front controller approach as it means I can abstract 
out the bootstrap code and not even have the "include this at the top of every 
page" stuff.  It does mean you want mod_rewrite if your app is going to be at 
all bookmarkable or googleable (you may or may not want it to be), but that's 
not a huge requirement.

Disclaimer: I was asking this same question about 3-4 years ago, and started 
looking for PHP systems to study to learn from.  I found Drupal, started using 
it directly, and haven't left yet. :-)  That's probably not a bad approach to 
take.  Find an existing system that "feels right" to you and run with that.  
You'll almost certainly get a better system out of it than trying to write 
everything yourself.  (I've done that before, too, and it was generally a 
disaster.)

[1] http://www.garfieldtech.com/blog/mvc-vs-pac
[2] http://en.wikipedia.org/wiki/Gang_of_Four_(software)

-- 
Larry Garfield
la...@garfieldtech.com

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to