[PHP] Variable (naming them) Functions.
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) [EMAIL PROTECTED] mailto:[EMAIL PROTECTED] www.phpbeginner.com http://www.phpbeginner.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP] Variable (naming them) Functions.
got a typo in my previous post: I was trying this: $fname = 'hello'; function { sprintf(%s, $fname) }($fname='') { Return I named you : $fname; } echo $fname($fname); But that doesn't matter... Thanks, waiting for your help. Maxim Maletsky Founder, Chief Developer PHPBeginner.com (Where PHP Begins) [EMAIL PROTECTED] www.phpbeginner.com -Original Message- From: Maxim Maletsky Sent: Friday, April 27, 2001 8:58 PM To: 'PHP General List. (E-mail)' Subject: [PHP] Variable (naming them) Functions. 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) [EMAIL PROTECTED] mailto:[EMAIL PROTECTED] www.phpbeginner.com http://www.phpbeginner.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP] Variable (naming them) Functions.
Why not use classes? If I understand you problem correctly, I think classes should solve your problem. Right? SED -Original Message- From: Maxim Maletsky [mailto:[EMAIL PROTECTED]] Sent: 27. apríl 2001 11:58 To: 'PHP General List. (E-mail)' Subject: [PHP] Variable (naming them) Functions. 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) [EMAIL PROTECTED] mailto:[EMAIL PROTECTED] www.phpbeginner.com http://www.phpbeginner.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP] Variable (naming them) Functions.
no classes CAN'T solve my problem: it is an abstraction layer. called as func_hello(); I want, inside func_hello() {} declare a new function based on what happened before func_hello() was called. In other words: I of course though about classes, and there is in fact a work around, but I need to know if 'function $var($arg) { return; }' syntax exists and what it is. in the docs there's nothing being said. Sincerely, Maxim Maletsky Founder, Chief Developer PHPBeginner.com (Where PHP Begins) [EMAIL PROTECTED] www.phpbeginner.com -Original Message- From: SED [mailto:[EMAIL PROTECTED]] Sent: Friday, April 27, 2001 9:53 PM To: Maxim Maletsky Cc: [EMAIL PROTECTED] Subject: RE: [PHP] Variable (naming them) Functions. Why not use classes? If I understand you problem correctly, I think classes should solve your problem. Right? SED -Original Message- From: Maxim Maletsky [mailto:[EMAIL PROTECTED]] Sent: 27. apríl 2001 11:58 To: 'PHP General List. (E-mail)' Subject: [PHP] Variable (naming them) Functions. 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) [EMAIL PROTECTED] mailto:[EMAIL PROTECTED] www.phpbeginner.com http://www.phpbeginner.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP] Variable (naming them) Functions.
Did you see create_function()? Not sure if this is what you are after, but http://www.php.net/manual/en/function.create-function.php Kirk -Original Message- From: Maxim Maletsky [mailto:[EMAIL PROTECTED]] Subject: [PHP] Variable (naming them) Functions. 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? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP] Variable (naming them) Functions.
create_function seems not letting you choosing it's name. am I right, or there's a way to say: create_function($name.$to.be, args, args, args)? Sincerely, Maxim Maletsky Founder, Chief Developer PHPBeginner.com (Where PHP Begins) [EMAIL PROTECTED] www.phpbeginner.com -Original Message- From: Johnson, Kirk [mailto:[EMAIL PROTECTED]] Sent: Saturday, April 28, 2001 1:03 AM To: 'PHP General List. (E-mail)' Subject: RE: [PHP] Variable (naming them) Functions. Did you see create_function()? Not sure if this is what you are after, but http://www.php.net/manual/en/function.create-function.php Kirk -Original Message- From: Maxim Maletsky [mailto:[EMAIL PROTECTED]] Subject: [PHP] Variable (naming them) Functions. 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? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP] Variable (naming them) Functions.
It lets you choose the variable name which you use when referencing the function, but the actual function name is set by PHP (as lambda_1, lambda_2, etc.) ? $test=myFunction; $$test = create_function('$a,$b','return log($a * $b);'); echo myFunction is .$myFunction(2,2).br; ? Kirk -Original Message- From: PHPBeginner.com [mailto:[EMAIL PROTECTED]] Sent: Friday, April 27, 2001 10:27 AM To: Johnson, Kirk; 'PHP General List. (E-mail)' Subject: RE: [PHP] Variable (naming them) Functions. create_function seems not letting you choosing it's name. am I right, or there's a way to say: create_function($name.$to.be, args, args, args)? Sincerely, Maxim Maletsky Founder, Chief Developer PHPBeginner.com (Where PHP Begins) [EMAIL PROTECTED] www.phpbeginner.com -Original Message- From: Johnson, Kirk [mailto:[EMAIL PROTECTED]] Sent: Saturday, April 28, 2001 1:03 AM To: 'PHP General List. (E-mail)' Subject: RE: [PHP] Variable (naming them) Functions. Did you see create_function()? Not sure if this is what you are after, but http://www.php.net/manual/en/function.create-function.php Kirk -Original Message- From: Maxim Maletsky [mailto:[EMAIL PROTECTED]] Subject: [PHP] Variable (naming them) Functions. 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? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Variable (naming them) Functions.
On Friday 27 April 2001 17:08, PHPBeginner.com wrote: no classes CAN'T solve my problem: it is an abstraction layer. called as func_hello(); I want, inside func_hello() {} declare a new function based on what happened before func_hello() was called. In other words: I of course though about classes, and there is in fact a work around, but I need to know if 'function $var($arg) { return; }' syntax exists and what it is. in the docs there's nothing being said. http://php.net/create_function (maybe together with a little wrapper: $foo = create_function (...); $FNames [$var] = $foo; function delta ($FuncName, $args) { return ${$FNames[$FuncName]} ($args); } ) But such a thing is an ugly hack and I'm sure you don't need it. -- Christian Reiniger LGDC Webmaster (http://sunsite.dk/lgdc/) Error 032: Recursion error - see error 032 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP] Variable (naming them) Functions. DONE! DONE! DONE!
Guys, I think LORD just looked down here in Tokyo, seen me still typing at 3.15am of Friday night, smoking the third pack of that nasty Marlboros, having no dinner, with no even a cup coffee remained... and sent to the list that GENIUS of Jason Murray who solved my problem. I know, Jason, you didn't mean it, but it REALLY helped me: $fname = 'hello'; $func = sprintf( function %s(\$v='') { Return \\$vBR\; }, $fname ); eval($func); echo $fname('Please print it please'); // And it did! a dynamic function! I got it. with eval() I can call it as I wish! I have no idea, HOW ON THE EARTH could I ever forget about magic EVAL(). I solved it! Everyone, take a note of this code, as it causes some sleepless nights and 'unhappy' girlfriends to some people. :-) Thanks everybody, Jason and Oliver in particular! Sincerely, Maxim Maletsky Founder, Chief Developer PHPBeginner.com (Where PHP Begins) [EMAIL PROTECTED] www.phpbeginner.com -Original Message- From: Christian Reiniger [mailto:[EMAIL PROTECTED]] Sent: Saturday, April 28, 2001 2:48 AM To: [EMAIL PROTECTED] Subject: Re: [PHP] Variable (naming them) Functions. On Friday 27 April 2001 17:08, PHPBeginner.com wrote: no classes CAN'T solve my problem: it is an abstraction layer. called as func_hello(); I want, inside func_hello() {} declare a new function based on what happened before func_hello() was called. In other words: I of course though about classes, and there is in fact a work around, but I need to know if 'function $var($arg) { return; }' syntax exists and what it is. in the docs there's nothing being said. http://php.net/create_function (maybe together with a little wrapper: $foo = create_function (...); $FNames [$var] = $foo; function delta ($FuncName, $args) { return ${$FNames[$FuncName]} ($args); } ) But such a thing is an ugly hack and I'm sure you don't need it. -- Christian Reiniger LGDC Webmaster (http://sunsite.dk/lgdc/) Error 032: Recursion error - see error 032 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
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 [EMAIL PROTECTED] wrote in message DC017B079D81D411998C009027B7112A015ED16A@EXC-TYO-01">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) [EMAIL PROTECTED] mailto:[EMAIL PROTECTED] www.phpbeginner.com http://www.phpbeginner.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Variable (naming them) Functions.
for point of reference regarding this thread : http://www.php.net/manual/en/functions.variable-functions.php regards, philip On Sat, 28 Apr 2001, Yasuo Ohgaki wrote: 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 [EMAIL PROTECTED] wrote in message DC017B079D81D411998C009027B7112A015ED16A@EXC-TYO-01">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) [EMAIL PROTECTED] mailto:[EMAIL PROTECTED] www.phpbeginner.com http://www.phpbeginner.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP] Variable (naming them) Functions.
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) [EMAIL PROTECTED] www.phpbeginner.com -Original Message- From: Yasuo Ohgaki [mailto:[EMAIL PROTECTED]] Sent: Saturday, April 28, 2001 3:27 AM To: [EMAIL PROTECTED] 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 [EMAIL PROTECTED] wrote in message DC017B079D81D411998C009027B7112A015ED16A@EXC-TYO-01">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) [EMAIL PROTECTED] mailto:[EMAIL PROTECTED] www.phpbeginner.com http://www.phpbeginner.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]