Doing a bit of a
(/wiki/#code) audit at [work](/wiki/#work) and going to remove this __call method from all my
(/wiki/#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;
}
⬅️ These Daily Mail squirrel stories always seem to be from Fareham :: Romanzo Criminale ➡️
Paulʼs blog - I live in A sleepy town in the deep South. Married + dad to two, I am a full-stack web engineer, and I do js / node, some ruby, other languages ect ect. My hobbies are pubs, parkrun, restaurants, home automation + other diy jiggery-pokery, history, family tree stuff, TV, squirrels, pirates, lego, + TIME TRAVEL.