RE: [PHP] Variable (naming them) Functions.
| From: | PHPBeginner.com | Date: | Fri, 27 Apr 2001 18:47:16 +0000 |
| Subject: | RE: [PHP] Variable (naming them) Functions. | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-50678@lists.php.net to get a copy of this message | ||
no, I knew that,
my problem was generating functions with dynamic names.
I solved it with a simple eval(), see my last post below;
Thanks, Yasuo,
Sincerely,
Maxim Maletsky
Founder, Chief Developer
PHPBeginner.com (Where PHP Begins)
maxim@phpbeginner.com
www.phpbeginner.com
-----Original Message-----
From: Yasuo Ohgaki [mailto:yohgaki@hotmail.com]
Sent: Saturday, April 28, 2001 3:27 AM
To: php-general@lists.php.net
Subject: Re: [PHP] Variable (naming them) Functions.
Variable functions?
<?php
foo () {
echo 'this is foo';
}
bar () {
echo 'this is bar';
}
$var = $HTTP_GET_VARS['fname'];
$$var();
?>
http://localhost/some_script.php?fname=foo
prints "this is foo";
http://localhost/some_script.php?fname=bar
print "this is bar"
Regards,
--
Yasuo Ohgaki
"Maxim Maletsky" <maxim.maletsky@japaninc.net> wrote in message
news:DC017B079D81D411998C009027B7112A015ED16A@EXC-TYO-01...
> Hello everyone:
>
> I was wondering, does anyone of you know a method to declare a function
> (give it a name) basing on a value acquired during run time?
>
> I tried using the syntax as of a variable function call:
>
>
> <snip>
>
> $fname = 'hello';
> function { sprintf("%s", $fname) }($arg='') {
> Return "I named you : $fname";
> }
> echo $fname($fname);
> # no luck...
>
>
> function {$fname}($arg='') { ....
> # nope...
>
>
> function $fname($arg='') { ....
> # neither...
>
> </snip>
>
> and so on... all parse errors...
>
>
>
> Any way to do it?
>
> I am looping an array with some function names checking if a function was
> declared already, and if not then declare, if yes - give a different name.
>
> I also went through these bibles:
> http://www.php.net/manual/en/ref.funchand.php
> <http://www.php.net/manual/en/ref.funchand.php>
> but found nothing that helps.
>
> Thanks in advance,
> Sincerely,
>
> Maxim Maletsky
> Founder, Chief Developer
> PHPBeginner.com (Where PHP Begins)
> maxim@phpbeginner.com <mailto:maxim@phpbeginner.com>
> www.phpbeginner.com <http://www.phpbeginner.com>
>
>
>
>
----------------------------------------------------------------------------
----
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
> For additional commands, e-mail: php-general-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
For additional commands, e-mail: php-general-help@lists.php.net
To contact the list administrators, e-mail: php-list-admin@lists.php.net