Re: Advice on Constants - Notice: Undefined Constant
| From: | Philip Olson | Date: | Wed, 09 Apr 2003 17:33:46 +0000 |
| Subject: | Re: Advice on Constants - Notice: Undefined Constant | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-143125@lists.php.net to get a copy of this message | ||
On Wed, 9 Apr 2003, Adam Douglas wrote:
> I'm currently developing a web site that stores two security levels of the
> client logged in. These security levels and including a few other variables
> are returning a PHP notice statement, "Notice: Undefined constant...". Now
> these variables are set at initial login into the web site and are stored
> into a the session file to reduce security checking routines and with the
> concept of why do a check again when we already know the value.
>
> To resolve this PHP notice issue I figured no big deal I will just declare
> the variable as a constant using define(). But by doing this correct me if
> I'm wrong you now no longer refer to the variable with a dollar sign and the
> variable name. Which is fine but can I store the constant into the session
> file?
>
> My concern and question is what the best direction to resolve this? At
> present if I just define the variables as a constant I get another PHP
> message "Notice: Undefined offset..." throughout my code when referencing my
> session variable (_SESSION[name]).
>
> Any advice would be greatly appreciated.
Use $arr['foo'] and not $arr[foo]. Read this:
http://www.php.net/types.string
With $arr[foo], PHP will first look for a constant named
foo and if it doesn't exist it provides the E_NOTICE and
then looks for a string named 'foo'. The above manual
entry describes this in detail.
You may also use error_reporting or prepend @ to suppress
the error.
Regards,
Philip