LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-12-2004, 04:15 AM   #1
antony_csf
Member
 
Registered: Jun 2004
Posts: 51

Rep: Reputation: 15
Unhappy php - call_user_func() problems


class TestClass{

function method_a(){
// do something
}

function method_b(){
// do something
}


function testcall(){
$functionname="method_a";

if(function_exists($function)){
echo "found<br />";
}else{
echo "not found<br />";
}
}

}


when I new an object it always echo not found??

How can I reference the class function??

anybody can help me ??

I think it should be something missing such as "$this->"

is it possible to do this ???

thx all!!
 
Old 07-12-2004, 05:52 AM   #2
datprogrammer
LQ Newbie
 
Registered: Jul 2004
Posts: 15

Rep: Reputation: 0
You're almost there, and thinking along the right lines...

Instead of
>>if(function_exists($function)){

(which should incidentaly have read if(function_exists($functionname)){)

you want if (method_exists($this,$functionname)) {


Classes have methods, even though php uses the keyword "function" to define them (as do several other laguages actually!) so because it's a class method rather than a normal function, you use method_exists() rather than funtion_exists()
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
More PHP problems :( arichardson Linux - Software 1 11-21-2005 03:24 PM
PHP problems PLEASE HELP!! mrosati Linux - Software 2 10-15-2004 04:01 AM
slackware, apache and PHP from .tgz - problems with PHP szymon Slackware 2 09-06-2004 04:57 PM
Problems with PHP :( AMMullan Linux - Software 7 12-02-2003 10:25 AM
PHP problems Mikessu Linux - Networking 2 09-20-2003 02:35 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:41 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration