Skip to content
Advertisement

Undefined variable: $_SESSION

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):

JavaScript

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?

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.

EDIT

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

JavaScript

Advertisement

Answer

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

in beforeFind and afterFind:

JavaScript

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

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement