Re: [PHP4BETA] References to functions inside a class?
[email protected] (Alan) Tue, 6 Jun 2000 00:38:20 +1000
| Newsgroups | php.version4 |
|---|---|
| Message-ID | <[email protected]> |
On Mon, 5 Jun 2000 10:41:57 +0300 (IDT), Stanislav Malyshev <[email protected]> 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. */