注意:未定义索引:loss_items [重复]

This is really weird. I know what Undefined index means. But look at this code.

This is what I got on the top of the script:

$__load = array(
    'loss_experience' => NULL,
    'loss_items' => NULL,
    'guild_info' => NULL,
    'skull_type' => NULL,
    'skull_time' => NULL,
    'blessings' => NULL,
    'direction' => NULL,
    'stamina' => NULL,
    'world_id' => NULL,
    'online' => NULL,
    'deletion' => NULL,
    'promotion' => NULL,
    'marriage' => NULL
);

then in class I got this:

   public function load($id)
    {
        global $__load;

        if($__load['loss_experience'] == NULL)
        {
            $loss = '';
            if(fieldExist('loss_experience', 'players')) {
                $loss = ', `loss_experience`, `loss_mana`, `loss_skills`';
            }

            $__load['loss_experience'] = $loss;
        }

        if($__load['loss_items'] == NULL)
        {
            $loss_items = '';
            if(fieldExist('loss_items', 'players')) {
                $loss_items = ', `loss_items`, `loss_containers`';
            }

            $__load['loss_items'] = $loss_items;
        }

and this is error I become:

Notice: Undefined index: loss_items in D:\xampp\htdocs\myaac\system\libs\pot\OTS_Player.php on line 145

Line 145 is this:

if($__load['loss_items'] == NULL)

What I did wrong?

When I comment this line:

$__load['loss_experience'] = $loss;

Then Notice is not showed. But I need to declare it.

@Edit I've tried this:

    public function load($id)
    {
        global $__load;
var_dump($__load);
        if($__load['loss_experience'] == NULL)
        {
            $loss = '';
            if(fieldExist('loss_experience', 'players')) {
                $loss = ', `loss_experience`, `loss_mana`, `loss_skills`';
            }

            $__load['loss_experience'] = $loss;
        }
var_dump($__load);
        if($__load['loss_items'] == NULL)
        {

Output of first var_dump is: NULL

And second var_dump: array(1) { ["loss_experience"]=> string(0) "" }

So it seems it doesn't see my top declared $__load variable.. but why?

</div>

'Undefined index' means you haven't stored a value in that element of your associative array '__load'. You didn't really define it when setting it to null.

Instead of testing for == null, use !isset() .

It is just a warning, so it's not breaking your code.