Page 1 of 1

Can i add a variable to a function name?

Posted: Thu Jun 18, 2015 6:06 am
by KaL
ok here is my example:

Code: Select all

function $Name($user = NULL)
     {
          (something working here);
     }
here is my Error:
Error: syntax error, unexpected '"', expecting '('
HINT: Maybe you forget to put a ; sign at the end of a line.

Error in "C:/wamp/www/nwe/modules/Expire/lib.php"
Line 15


Tried:

Code: Select all

function "$Name"($user = NULL)
     {
          (something working here);
     }

Code: Select all

function {$Name} ($user = NULL)
     {
          (something working here);
     }

Code: Select all

function ".$Name." ($user = NULL)
     {
          (something working here);
     }

ALL FAIL! Is there any other ways?

Re: Can i add a variable to a function name?

Posted: Thu Jun 18, 2015 10:59 am
by KyleMassacre
If you use PHP >= 5.3 you can use an Anonymous Function described here http://php.net/manual/en/functions.anonymous.php. I think that it was you are trying to do

Re: Can i add a variable to a function name?

Posted: Thu Jun 18, 2015 3:15 pm
by hallsofvallhalla
I would say there is a better way to try to do what you are doing. Variable functions may get messy,

Re: Can i add a variable to a function name?

Posted: Thu Jun 18, 2015 5:21 pm
by KyleMassacre
hallsofvallhalla wrote:I would say there is a better way to try to do what you are doing. Variable functions may get messy,
I heard they can get a little crazy so I have never used them.

Kal, tell us what you are trying to do and maybe we can come up with a better solution

Re: Can i add a variable to a function name?

Posted: Thu Jun 18, 2015 6:57 pm
by KaL
I'm creating a timer module:

Allowing admin to create a time function that can block a module when it is expire. No coding involed.

It will show the remaining time frame that it will be expire.

Well guys! I finished it. I got it to work but now I just need to exported it out and finish the rest of the add on.

Can I sell it? LOL!