Farewell missing method magic, we hardly new you
Home
Doing a bit of a code audit at work and going to remove this __call method from all my code. I put it in so I could do swanky ruby on rails style magic methods like $items = $this->fetch_bundle_by_code_and_name( 'LGWHIL', 'champagne' )
without having to write the method with that name. But it's a bit slower and I never actually used it so it's going. Saving it here for prosperity. Maybe I'll use it again one day:
public function __call( $name, $param ) {
$return = '';
$regexp = '/_(by|and)_(' . implode( '|', array_keys( $this->fields )) . ')/';
if (( strpos( 'fetch_' . $this->table . '_', $name ) == 0 ) and ( preg_match_all( $regexp, $name, $m ))) {
$params_for_fetch = array();
foreach ( $m[2] as $key => $var ) {
$params_for_fetch[ $var ] = $param[ $key ];
}
if ( count( $params_for_fetch )) {
$return = $this->fetch( $params_for_fetch );
}
}
return $return;
}
pauly :: 2011 :: Comment / reply
Over to you, discussion about anything local, but please be considerate... Folkestone on TV, Kent gigs, Find a flatmate, rent a room, property queries, current news, what's new, local events, for sale, local services, what I like about Folkestone, ask questions, offer advice, plug yourself... the more it's used the more useful a resource it will become. If you want a gig listed click here to add it (fixed now!), or just click here to post a message...

