dtl19910708 2017-05-18 18:05
浏览 94

注意:未定义索引: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>
  • 写回答

1条回答 默认 最新

  • douqingji3026 2017-05-18 18:35
    关注

    '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.

    评论

报告相同问题?

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么