Can i add a variable to a function name?

General Chat, Comments
Post Reply
KaL
Posts: 344
Joined: Mon Jan 13, 2014 5:44 am

Can i add a variable to a function name?

Post 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?
User avatar
KyleMassacre
Posts: 573
Joined: Wed Nov 27, 2013 12:42 pm

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

Post 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
User avatar
hallsofvallhalla
Site Admin
Posts: 12026
Joined: Wed Apr 22, 2009 11:29 pm

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

Post by hallsofvallhalla »

I would say there is a better way to try to do what you are doing. Variable functions may get messy,
User avatar
KyleMassacre
Posts: 573
Joined: Wed Nov 27, 2013 12:42 pm

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

Post 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
KaL
Posts: 344
Joined: Mon Jan 13, 2014 5:44 am

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

Post 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!
Post Reply

Return to “General”