未定义变量:$_SESSION [英] Undefined variable: $_SESSION

查看:45
本文介绍了未定义变量:$_SESSION的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在核心 CakePHP 文件中尝试引用从未设置或未设置的会话时收到 E_NOTICE 错误(cake/libs/cake_session.php 第 372 行):

I'm getting E_NOTICE errors in a core CakePHP file when it tries to reference a never-set or unset session (cake/libs/cake_session.php line 372):

function read($name = null) {
    if (is_null($name)) {
        return $this->__returnSessionVars();
    }
    if (empty($name)) {
        return false;
    }
    $result = Set::classicExtract($_SESSION, $name);
}

我搜索了我的代码(在 app/目录中),但找不到对 $_SESSIONsession_destroy 的引用.我错过了什么吗?

I've done a search through my code (in the app/ directory) and I can't find references to $_SESSION or session_destroy. Am I missing anything?

当我尝试运行任何单元测试时会出现此错误.这……正常吗?我已经清除了 cake/ 目录并将其替换为另一个(相同版本),以确保我没有无意中修改了核心文件中的任何内容,但我仍然遇到相同的错误.我不确定这只是框架中的缺陷还是其他什么.

This error shows up when I try to run any unit tests. Is this...normal? I've cleared out the cake/ directory and replaced it with another one (same version) just to make sure that I hadn't inadvertently modified anything in the core files, but I still get the same error. I'm not sure if this is just a flaw in the framework or something else.

编辑

这是在命令行上测试运行的结果:

Here are the results of the test run on the command line:

Welcome to CakePHP v1.3.11 Console
---------------------------------------------------------------
App : app
Path: /var/www/program/app
---------------------------------------------------------------
CakePHP Test Shell
---------------------------------------------------------------
Running app case models/owners_equity
E_NOTICE: Undefined variable: _SESSION in /var/www/program/cake/libs/cake_session.php on line 372
E_NOTICE: Undefined variable: _SESSION in /var/www/program/cake/libs/cake_session.php on line 372
ERROR->Unexpected PHP error [Undefined variable: _SESSION] severity [E_NOTICE] in [/var/www/program/cake/libs/cake_session.php line 372]
    in testGenerateOwnerWithdrawals
    in BalanceTestCase
    in /var/www/program/app/tests/cases/models/owners_equity.test.php

ERROR->Unexpected PHP error [Undefined variable: _SESSION] severity [E_NOTICE] in [/var/www/program/cake/libs/cake_session.php line 372]
    in testGenerateOwnerWithdrawals
    in BalanceTestCase
    in /var/www/program/app/tests/cases/models/owners_equity.test.php

推荐答案

结果发现 AppModel 中有一些额外的代码把事情搞砸了:

Turned out there was some extra code in the AppModel that was messing things up:

beforeFindafterFind中:

App::Import("Session");
$session = new CakeSession();
$sim_id = $session->read("Simulation.id");

我不知道为什么,但这就是问题所在.删除这些行解决了我遇到的问题.

I don't know why, but that was what the problem was. Removing those lines fixed the issue I was having.

这篇关于未定义变量:$_SESSION的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆