ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Challenge 2 : moveable function arguments

July 10, 2008 6:18am

Subscribe [0]
  • #46 / Jul 12, 2008 1:55am

    Randy Casburn

    997 posts

    Ditto my previous post.  All in fun and stretching the mind a little. 😏

    (but I still don’t know what the hell he really wants—teehee)

  • #47 / Jul 12, 2008 2:05am

    thurting

    213 posts

    Hi Randy.  I understand your point, but mine is that there are more efficient ways to accomplish the task.

    That being said, in the case of your SQL example, the solution you provide would not be as extensible and clean as others.  For example, in the Zend Framework (CI has DB abstraction too) you would accomplish your example with:

    $table->fetchAll($table->select()->where('var1 = ?', 'val1')
                                     ->where('var2 = ?', 'val2')
                                     ->order('var1')
                                     ->limit(10, 0));

    After calling $table->select(), you can order the methods any way you want.  Method chaining is nice! In addition, you can create extremely complex queries using other methods and alternative implementations.  Now, aside from the ability to extend these methods and provide any functionality you desire, I think you’ll find that an implementation as such is much more clean and dynamic than the one you provided.  I know you were just providing an example off the cuff, but I think you can see my point.

    In addition, PHP provides method overloading with __call(), so if you really need to create some wild methods, you should use that.  For example, I could easily set up something with __call() to accept all of the following methods:

    addressName($name), addressStreet($street), addressNameAndStreet($name, $street), addressStreetAndName($street, $name), addressXAndYAndZ($x, $y, $z), etc.

    At the end of the day, it really depends on what you are trying to do, but some solutions are better than others.

  • #48 / Jul 12, 2008 3:23am

    Randy Casburn

    997 posts

    Agreed.

    If we had 10 oreo cookies we’d have 10 ways to eat them!

    Thanks for the debate.

    Randy

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases