RE: [PHP] add functions to a class
On 21 September 2006 10:19, Thomas Munz wrote: > This will not work. > > $this->bla(); > > This is a PHP Syntax and tries to get the Class method, PHP dont look > for a variable name at all! > > It seams me strange also, that you try this, you should create the > method for the class itself, or extend it. > > But this shoul work: > > class Test { > function Test () { >$funcName = 'writeFoo'; >$$funcName = create_function ('', 'echo ("foo.\n");'); >$writeFoo (); $writeFoo2 = $writeFoo; >$writeFoo2 (); >$this->writeFoo = $writeFoo; >return call_user_func($this->writeFoo, 'arg1, arg2'); } You could also try {$this->writeFoo}() -- not certain about this (OOP is not my big thing), but worth a try. Cheers! Mike - Mike Ford, Electronic Information Services Adviser, Learning Support Services, Learning & Information Services, JG125, James Graham Building, Leeds Metropolitan University, Headingley Campus, LEEDS, LS6 3QS, United Kingdom Email: [EMAIL PROTECTED] Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211 To view the terms under which this email is distributed, please go to http://disclaimer.leedsmet.ac.uk/email.htm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] add functions to a class
This will not work. $this->bla(); This is a PHP Syntax and tries to get the Class method, PHP dont look for a variable name at all! It seams me strange also, that you try this, you should create the method for the class itself, or extend it. But this shoul work: class Test { function Test () { $funcName = 'writeFoo'; $$funcName = create_function ('', 'echo ("foo.\n");'); $writeFoo (); $writeFoo2 = $writeFoo; $writeFoo2 (); $this->writeFoo = $writeFoo; return call_user_func($this->writeFoo, 'arg1, arg2'); } } on Wednesday 20 September 2006 15:07, Kelsang Tsenle wrote: > Hi all, > > I tried to add functions to a class, but it doesn't seem to work. Here's > an example: > > class Test { > > function Test () { >$funcName = 'writeFoo'; >$$funcName = create_function ('', 'echo ("foo.\n");'); >$writeFoo (); >$writeFoo2 = $writeFoo; >$writeFoo2 (); >$this->writeFoo = $writeFoo; >$this->writeFoo (); > } > } > > $test = new Test (); > ?> > > This outputs: > foo. > foo. > PHP Fatal error: Call to undefined method Test::writeFoo() in > /test.php on line 11 > > > Both $writeFoo () and $writeFoo2 () are executed, so it principally > works, but once used in the object, it doesn't work anymore. > > > Any idea how that is supposed to work? > > > Gratefully, > Tsenle -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] add functions to a class
Hi all, I tried to add functions to a class, but it doesn't seem to work. Here's an example: writeFoo = $writeFoo; $this->writeFoo (); } } $test = new Test (); ?> This outputs: foo. foo. PHP Fatal error: Call to undefined method Test::writeFoo() in /test.php on line 11 Both $writeFoo () and $writeFoo2 () are executed, so it principally works, but once used in the object, it doesn't work anymore. Any idea how that is supposed to work? Gratefully, Tsenle -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php