473,326 Members | 1,972 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

How to check the user function existance?

Hi,
I created a web-page which contains functions like add(),sub(),divide().. consider I am passing two value and functions name from first page. Then I received the values from first page and I want to check whether the function is exist or not. If exist means, the resultant value has to produce otherwise it has to display as "Not a valid function"..... How can I achieve this. Is any function to check availability.
Nov 11 '09 #1

✓ answered by Dormilich

function_exists()

if you were to use objects (object methods), you can check against an interface or a class definition.

4 1665
Dormilich
8,658 Expert Mod 8TB
function_exists()

if you were to use objects (object methods), you can check against an interface or a class definition.
Nov 11 '09 #2
I cant get clearly. Could you explain with code snippet.
Nov 11 '09 #3
Dormilich
8,658 Expert Mod 8TB
Expand|Select|Wrap|Line Numbers
  1. if (!function_exists("doSomething"))
  2. {
  3.     throw new Exception("You can’t do something!");
  4. }
Expand|Select|Wrap|Line Numbers
  1. interface iTest
  2. {
  3.     public function doSomething();
  4. }
  5.  
  6. class Abc
  7. {
  8.     private $someValue;
  9.  
  10.     public function __construct(iTest obj)
  11.     {
  12.         this->someValue = obj->doSomething();
  13.     }
  14. }
  15.  
  16. class Test implements iTest
  17. {
  18.     public function doSomething()
  19.     {
  20.         return "something";
  21.     }
  22. }
  23.  
  24. $y = new Abc(new stdClass); // throws an error
  25. $y = new Abc(new Test); // doesn’t throw an error
Nov 11 '09 #4
Markus
6,050 Expert 4TB
For classes you might also use method_exists().
Nov 11 '09 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

18
by: Dino | last post by:
dear all, i've created an application for a customer where the customer can upload ..csv-files into a specified ftp-directory. on the server, a php-script, triggered by a cronjob, reads all the...
1
by: Patrick Kowalzick | last post by:
Hello all, I want to test run-time if a template function for a special type exists. See example below. The checkfoo function is where I need some hints. Regards, Patrick #include...
4
by: KathyB | last post by:
Sorry this is a bit of a repost because I wasn't quite accurate in my original. I have an hmtl page with a function to see if there are any input type=text boxes. If so, that means a user did...
2
by: sosh | last post by:
Hi, Sorry for the simple question, but could anyone tell me the best way to test for the existance of an element with a particular attribute value (id) ? Thanks
7
by: Ajit | last post by:
Is there anyway to check for existance of a file on different machine. i.e. we have a data file (text file) thats stored on some other machine as its not to be exposed in case the web server is...
10
by: Dieter Pelz | last post by:
Hallo, what is the best way to check the installation of mfc80 and vcrt sidebyside assemblies? Best Regards, Dieter Pelz
16
by: king kikapu | last post by:
Hi to all, in statically-types languages, let's say C# for example, we use polymorphism through interfaces. So we define an interface I with method M and then a class C that implements I...
14
by: Dan | last post by:
Hello, we have an intranet application using Windows Integrated Authentification. When an user starts the application, he gets a form for inputting data. The first time he does that, the...
1
by: soulfly73 | last post by:
hello All, I have an question, I'm very newwhen it comes to ASP.net. I am building an site where I want to check on the existince of an image in an certain directory. No I have some questions...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.