Re: [PHP4BETA] References to functions inside a class?
| From: | Alan | Date: | Mon, 05 Jun 2000 14:38:20 +0000 |
| Subject: | Re: [PHP4BETA] References to functions inside a class? | ||
| Groups: | php.version4 | ||
| Request: | Send a blank email to php-version4+get-16150@lists.php.net to get a copy of this message | ||
On Mon, 5 Jun 2000 10:41:57 +0300 (IDT), Stanislav Malyshev <stas@zend.com> wrote:
>
> J>> {
> J>> if($limit)
> J>> $this->query() = &$this->query_l();
> J>> else
> J>> $this->query() = &$this->query_u();
> J>> }
> J>> }
> J>> ?>
> J>>
> J>> PS: I'll even accept a pointer to discussion saying that it CAN'T be
> J>> done...I know someone on this list was discussiing this at one pont, but I
> J>> don't recall the discussion.
>
> You can't have reference to function. However, you can do the following:
>
> $this->call_query = "query_l";
>
> $this->$call_query($params)
shouldnt this be sematically equiv to $this->$this->call_query($params)...
>
> i.e., call by variable name.
>
>
another variation on the theme
class Class{
var which_query_func;
function Class($limit){
if($limit){
$this->which_query_func="query_l";
}
else{
$this->which_query_func="query_u";
}
}
function query($arg){
$query=$this->which_query_func;
return $this->$query($arg);
}
function query_l($arg){
// limit query
}
function query_u($arg){
// no limit query
}
}
Now $inst->query() will result in the correct function being called.
Regards,
Alan van den Bosch
Sanguis Pty Ltd
/* All generalizations are false. */