Paul Scott wrote: > I have googled around a bit, but not really found anything useful... > > Which is more efficient? A case switch or a $$method style method? > both examples are just boilerplate 'frontcontroller' code that do pretty much nothing of themselves. - in terms of speed you will notice nothing. in principle OO code is a little slower because creating objects has quite a lot of overhead as compared to just calling functions (if your just creating 1 or 2 objects it's not measurable) - but then it all depends on what the code inside object/function actually does! > An example: > > switch($action) { > case 'edit': > //do some stuff > ....... > return "edit_tpl.php"; > > case 'whatever': > //blah > ...... > ...... > } > > OR: > > $method=$this->convertToMethod($action); my guess is that there will be a switch statement in convertToMethod() to 'convert' $action into $method. so it effectively does what you example switch() is doing. ask yourself whether you prefer to hide some of the complexity of what your scripts are doing inside the bowels of an object - or whether you prefer to use procedural code. either is fine, it's up to you - just make sure you write neat, well-documented & properly thoughtout code and even the guy that has to maintain your stuff 2 years from now will be happy regardless of the paradigm you chose. > unset($action); > return $this->$method(); > > Hope this is reasonably clear... Note the return on the latter code. > > If anyone has any ideas around this, please let me know! Are there > underlying security risks in doing it this way? $action is coming from the client (eg. a GET/POST variable) - sanitize it! validate it! use 'whitelisting' to trigger a reaction (rather than using the actual value). don't trust data coming from outside your script/server (don't trust that either ;-). > > --Paul > > > > ------------------------------------------------------------------------ > > All Email originating from UWC is covered by disclaimer http://www.uwc.ac.za/portal/uwc2006/content/mail_disclaimer/index.htm > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php