RE: [PHP] Calling class functions using string variables?
| From: | Nick Richardson | Date: | Sun, 22 Sep 2002 19:57:50 +0000 |
| Subject: | RE: [PHP] Calling class functions using string variables? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-117196@lists.php.net to get a copy of this message | ||
Nevermind, I have finally figured it out... I was missing a ; in the
eval statement.
For anyone who wanted to know, there's 2 ways...
1) the long way
$clName = "myClass";
$fuName = "myFunc";
$t = new $clName;
$t->$fuName();
unset($t);
2) the short way
$cl = "myClass";
$fu = "myFunc";
eval("$cl::$fu();");
-----Original Message-----
From: Nick Richardson [mailto:esoteric.web@gte.net]
Sent: Sunday, September 22, 2002 12:50 PM
To: 'PHP General'
Subject: [PHP] Calling class functions using string variables?
Hi,
Anyone know if it's possible to call a class function using 2 string
variables WITHOUT instantiating the class?
i.e.:
$clName = "myClass";
$fuName = "myFunc";
$clName::$fuName();
I have tried several different combinations of eval and {} and just
about everything else I can think of… and they all give parse errors
when the class name is a string var. (i.e. myClass::$fuName() works fine
(as expected) but $clName::myFunc() does not). Everytime it doesn't
work, it just gives a simple parse error.
Any suggested are much appreciated!
Thanks in advance!
//Nick Richardson
// esoteric.web@gte.net
---
Outgoing mail is certified Virus Free. Can McAfee do that? - Hell NO!
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.386 / Virus Database: 218 - Release Date: 9/9/2002
---
Outgoing mail is certified Virus Free. Can McAfee do that? - Hell NO!
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.386 / Virus Database: 218 - Release Date: 9/9/2002