/    Sign up×
Community /Pin to ProfileBookmark

help with function call

Hello Experts,
I have a problem.I have a string name of a function.i want to call that function.
But donot know how.i am trying to append ‘()’ to the end but no Luck.
Any ideas…
thanking you all.
for ex:
<?php
//i have the function name as string.
$fname = ‘getvalue’;
//i want to call this [COLOR=”Red”]getvalue().[/COLOR]
$fname.'()’;
//this throws an error.
?>

to post a comment
PHP

6 Comments(s)

Copy linkTweet thisAlerts:
@Phill_PaffordMay 16.2008 — $fname = getvalue();
Copy linkTweet thisAlerts:
@akaash19authorMay 17.2008 — ofcourse that is the normal way but i am getting this function name string dynamically.I did it to make simple

<?php

//i have the function name as string.

$fname = getfunctionname();

//i want to call the function.

$fname.'()';

//this throws an error.

?>

let us say that getfunctionname() returned me 'akaash'.

then i want to call akaash().

thanks all
Copy linkTweet thisAlerts:
@NogDogMay 17.2008 — [url=http://www.php.net/manual/en/function.call-user-func.php]call_user_func[/url](), perhaps?
Copy linkTweet thisAlerts:
@Phill_PaffordMay 17.2008 — not sure I am following, are you trying to create a function dynamically?

does the akaash() function already exists? or are you trying to make the function from the name passed in?
Copy linkTweet thisAlerts:
@akaash19authorMay 21.2008 — First..thanks for replying phill and nogdog.

Yes..the function already exists..

i tried call_user_func() and it really solved the problem.

Interestingly i came across on php concept of php variable functions.

reading further i came to knw it is even faster than call_user_func().

all we have to do is to append () to the function name string and it works.

http://php.mirrors.ilisys.com.au/manual/en/functions.variable-functions.php

SO all i did was

<?php

$fname = getfunctionname();

$fname();

?>

and it worked..

again thanks to you guys...i just love this forum as i always get replies and got many problems solved..

/www.webdeveloper.com rokssss..
Copy linkTweet thisAlerts:
@Phill_PaffordMay 30.2008 — Here is another article that might help if you still need to do this

http://roshanbh.com.np/2008/05/execute-php-code-textbox-textarea.html
×

Success!

Help @akaash19 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...