note 102945 deleted from reserved.keywords by danbrown
| From: | danbrown@php.net | Date: | Wed, 16 Mar 2011 14:39:29 +0000 |
| Subject: | note 102945 deleted from reserved.keywords by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-177933@lists.php.net to get a copy of this message | ||
Note Submitter: Chris
----
As another note, to the previously mentioned comment, here's another alternative that will
allow you to map names based on an array (a private map variable) this also degrades pretty well
into PHP 4 versions, you can use this to your advantage handling slow adopters, as well as early
adopters.
This is an example from a download class I'm building for CodeIgniter
<?php
class Download {
private $ci = NULL;
private $map = array(
'file' => '_obscure_or_referenced_name',
'list' => '_obscure_or_referenced_name_two',
);
public function __construct($config=array()) {
/* Perform an action or so */
}
/* Force Download a file */
public function _obscure_or_referenced_name($arg1,$arg2=NULL){
/* Do Download Code Here */
}
public function _obscure_or_referenced_name_two($arg){
/* Do Download Code Here */
}
public function __call($func, $args)
{
if(!method_exists($this,$func)){
return call_user_func_array(array($this,$func),$args);
} else {
if(in_array($func,$this->map)){
return call_user_func_array(array($this,$this->map[$func]),$args);
} else {
trigger_error("Call to undefined method ".__CLASS__."::$func()",
E_USER_ERROR);
}
}
}
}
?>
I believe this to be a slightly better alternative to the previously mentioned one. There are some
debates on the use of call_user_func_array (http://php.net/call_user_func_array) in a class like
this, it does have some small performance differences, but not enough in my opinion to warrant using
the harder/fixated route. this gives expansion a simple touch.