Jump to content

Constant Value Request Function


orbstra

Recommended Posts

Hey! I need a function in my program which returns the value of a given constant name. All my constants are in an external file. I need this function to work like, if you need to use the value of a certain constant you use option_request('TP01') . The TP01 is an option in the config file, it is a constant. this is what I have so far, it's more or less nothing, I am in very need of help.
[code]
function opt($num)
{
require_once('guav-config/config.php');
                        $return = const $num;
return $return;
}
[/code]

thanks
Link to comment
https://forums.phpfreaks.com/topic/32476-constant-value-request-function/
Share on other sites

Use the defined(...) function. From the PHP manual -
[code]<?php
/* Note the use of quotes, this is important.  This example is checking
* if the string 'CONSTANT' is the name of a constant named CONSTANT */
if (defined('CONSTANT')) {
    echo CONSTANT;
}
?> [/code]
Edit: Sorry, I mis-read the question. See the correct answer in the following post -
[quote author=ShogunWarrior link=topic=120590.msg494711#msg494711 date=1167678111]
You use the function [b]constant()[/b]
e.g:
[code]
echo( 'The value of constant TP01 is' . constant("TP01") );
[/code]
[/quote]

I keep gettin an error when I use my function (code below), like this:
[code]
//Used like:
include(get::dir('theme') . '/' . get::opt('TP01') . '/head.php');

//Function found later in the script
function opt($num) //TODO: Finish get::opt() function
{
require(get::dir('config') . 'config.php');
$return = constant($num);
global $return;
return $return;
}
[/code]

this is the error I get:
[code]
Warning: constant() [function.constant]: Couldn't find constant TP01 in C:\Documents and Settings\Administrator\My Documents\My Projects\Web Projects\Guava\guav-includes\guav_library.php on line 224
[/code]

TP01 is clearly defined in config.php as
[code]
//The theme you would like to use (guav-template/)
DEFINE("TP01", "default");
[/code]

thanks

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.