Jump to content

Constants on a Function


fusionpixel

Recommended Posts

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 function

checkConstant();
[/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?
Link to comment
Share on other sites


while calling the function as
checkConstant(MY_CONSTANT);
the value MY_CONSTAN  got substituded and the value passed is
the value of it eg in FIRST_NAME the value 'Fusion Pixel'
is passed which is not defined

so you need to pass it as
checkConstant('MY_CONSTANT');

inside the function you need to print it as


function checkConstant($theConstant)
{   
if (defined($theConstant))
{
echo constant ($theConstant);
}

}

Try this
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.