Re: variable functions as class members

From: Date: Wed, 14 Jun 2000 06:25:51 +0000
Subject: Re: variable functions as class members
References: 1  Groups: php.dev 
Request: Send a blank email to php-dev+get-21290@lists.php.net to get a copy of this message
On Wed, 14 Jun 2000 00:48:13 -0700 Phil Glatz <phil@glatz.com> wrote: > *This message was transferred with a trial version of CommuniGate(tm) Pro* > I have a global function called 'globe' > > Within a class, I have a member function called 'foo' > > Another member function, 'test', has a variable function call within it, > with the name of the function to call as a string argument to it. > > I can refer to the global function 'globe' as an argument to it, and it > will execute. But what I'd really like to do would be able to call test() > from another function within the class, and use the 'foo' member function > of the same class as its argument. > > Is this possible? What would the syntax be? > > # member function > function test($arg) { > $arg(); > } > > # member function > function foo() { > # does something... > } > > this works: > $this->test('globe'); > > but how could I refer to $test->foo() as an argument to test? > this won't work: > $this->test('this->foo'); > > any kind of syntactical hack to do this? I'm using php4 > Hi, this is working with latest cvs: <?php class foo { function test($arg) { call_user_func($arg); } function bar() { print "Executing bar!\n"; } } function globe() { print "Executing globe!\n"; } $f = new foo; $f->test("globe"); $f->test(array($f, "bar")); ?> Regards, Stefan Livieratos

« previous php.dev (#21290) next »