I implemented both magic and non-magic methods (the former simply calls
the latter).  I knew that there was demand for the magic methods.  But
it's totally optional, and in most cases it is merely a matter of
preference.

Here are some considerations for using the magic vs. non-magic methods:

- Some people like the readability of magic methods; they are somewhat
Rails-like.

- There is slightly more overhead to using the magic methods.  It's
pretty small though, just a couple of calls to preg_match() and then a
function call to the appropriate non-magic method.

- The non-magic methods accepts a Table object, as alternative to a
string naming the Table class.  Sometimes this could be convenient.

- Editors that perform code-completion have a hard time guessing at
magic methods or magic properties.  If you prefer to use
code-completion, then you should use the non-magic methods.

- If you choose rule keys in the $_referenceMap containing characters
that are illegal to use in a PHP method name, you can't use the rule
keys in magic method calls, but you can still use them in non-magic
methods.  Example:

  class MyTable extends Zend_Db_Table_Abstract
  {
    protected $_referenceMap = array(
      'The Rule' => array( ... )
    );
  }

  $parentRow->findDependentRowset('MyTable', 'The Rule'); // works
  $parentRow->findMyTableByThe Rule(); // doesn't work

A rule key with a space in it, like 'the rule' above, doesn't work well
when you try to use it in a magic method.  If you want to use magic
methods, name your rule keys using only characters that are legal for
normal PHP method names.

Regards,
Bill Karwin

> -----Original Message-----
> From: Troy Marker [mailto:[EMAIL PROTECTED]
> Sent: Sunday, March 25, 2007 9:10 AM
> To: [email protected]
> Subject: [fw-general] Use magic methods in Db_Table relationships
> 
> I am trying to wrap my head around the new relationship function in
> Db_Table. They are a welcome addition.
> 
> My question is what is better. Calling the relation normally or by
using
> the magic functions. I feel there is more overhead in the magic
> function, as they need to determine what rules to apply.
> 
> I can see merit in both ways. I was just wondering what other people
> thougut/do.
> 
> Thanks for the input.
> 
> Regards,
> Troy

Reply via email to