At 16:31 08.11.2002, R B spoke out and said:
--------------------[snip]--------------------
>This is not the same question i asked yesterday.
>
>When i set error_reporting  =  E_ALL and display_errors = On in my php.ini, 
>i get the next message:
>
>"Notice: Undefined variable: varname in ....".
>
>How can i fix this problem without setting error_reporting  =  E_ALL & 
>~E_NOTICE and/or display_errors = Off, or what way do you think is the best 
>to resolve this problem?
--------------------[snip]-------------------- 

But it's the same answer ;-)
If you want to be completely warning-and-notice-free, you need to define
the variable before accessing it:

        // this will give a notice
        echo $undefined_var;

        // and this won't
        $define_var = 'some data, or simply put "null" here';
        echo $defined_var;

The same holds true for array indices:

        $test_array = array('One', 'Two', 'Three');

        // this will give a notice
        echo $test_array[3];

        // and this won't
        echo $test_array[2];

        // and this won't as well
        if (array_key_exists(3))
                echo $test_array[3];

Get the idea? IMHO it's complete overkill with PHP to predefine variables
since they're auto-initialized with NULL when used first. These notices are
only for the development cycle, to aid us in spotting a problem where you
expect some data to be there, but it aint because the variable name has
been mistyped...


-- 
   >O Ernest E. Vogelsinger 
   (\) ICQ #13394035 
    ^ http://www.vogelsinger.at/

Reply via email to