fusionpixel Posted December 8, 2006 Share Posted December 8, 2006 I am trying to create a function that will check if a Constant has been defined.one way to do it is:[code]#define Constant:define('FIRST_NAME', 'Fusion Pixel');[/code][code]if ( defined('FIRST_NAME') ){ echo FIRST_NAME;}[/code]But I need a function to call it through the code:[code]function checkConstant(){ if ( defined('FIRST_NAME') ) { echo FIRST_NAME; }}#now call the functioncheckConstant();[/code]But the problem is that if I have different constants that I need to check it would be nice to have a function that I can pass the function to without having to rely on one function at the time. Something like[code]checkConstant(MY_CONSTANT);[/code]But it doesn't work:[code]function checkConstant($theConstant){ if ( defined($theConstant) ) { echo FIRST_NAME; }}[/code]The function above failes silently.Any ideas? Quote Link to comment Share on other sites More sharing options...
logu Posted December 8, 2006 Share Posted December 8, 2006 while calling the function ascheckConstant(MY_CONSTANT);the value MY_CONSTAN got substituded and the value passed isthe value of it eg in FIRST_NAME the value 'Fusion Pixel'is passed which is not definedso you need to pass it as checkConstant('MY_CONSTANT');inside the function you need to print it asfunction checkConstant($theConstant){ if (defined($theConstant)) { echo constant ($theConstant); } }Try this Quote Link to comment Share on other sites More sharing options...
fusionpixel Posted December 8, 2006 Author Share Posted December 8, 2006 Nice, I can't believe it. so close yet so far.I tried to read books and the PHP manual to figure this out but still for some reason I couldn't figure it out.Thanks for the tip, it works like a charm. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.