Symfony 2 - 致命错误:无法在 C:\...\app\cache\dev\classes.php 第 532 行重新声明类 SessionHandlerInterface
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14689307/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Symfony 2 - Fatal error: Cannot redeclare class SessionHandlerInterface in C:\...\app\cache\dev\classes.php on line 532
提问by Egel
After reinstalling my wamp environment this error message is showing on screen after I open app_dev.php:
重新安装 wamp 环境后,打开 app_dev.php 后,屏幕上显示此错误消息:
Fatal error: Cannot redeclare class SessionHandlerInterface in C:...\app\cache\dev\classes.php on line 532
致命错误:无法在第 532 行的 C:...\app\cache\dev\classes.php 中重新声明类 SessionHandlerInterface
Does anyone have any clue what is going wrong?
有谁知道出了什么问题?
回答by xger86x
I solved it clearing the cache:
我解决了清除缓存:
app/console cache:clear
回答by Matteo Tassinari
PHP version 5.4introduced a new session management system based on an interface called SessionHandlerInterfaceand it would seem that your Symfony2 code declares a class with the very same name in the global namespace, so there is a name clash.
PHP 5.4版引入了一个基于调用接口的新会话管理系统,SessionHandlerInterface看起来您的 Symfony2 代码在全局命名空间中声明了一个同名的类,因此存在名称冲突。
Here are the docs: http://www.php.net/manual/en/class.sessionhandlerinterface.php
以下是文档:http: //www.php.net/manual/en/class.sessionhandlerinterface.php
SessionHandlerInterface is an interface which defines a prototype for creating a custom session handler. In order to pass a custom session handler to session_set_save_handler() using its OOP invocation, the class must implement this interface.
SessionHandlerInterface 是一个接口,它定义了用于创建自定义会话处理程序的原型。为了使用其 OOP 调用将自定义会话处理程序传递给 session_set_save_handler(),该类必须实现此接口。
回答by Scott Daniel
The simple clear cache didn't work for me. It required that the production cache be cleared using the command below.
简单的清除缓存对我不起作用。它要求使用以下命令清除生产缓存。
php app/console cache:clear --env=prod --no-debug
回答by rextof _prifex
Just try to clear the Symfony2 cache with the one (or all) the commands below :
只需尝试使用以下一个(或全部)命令清除 Symfony2 缓存:
php app/console cache:clear --env=prod --no-debug (on production mode)
or / and
或 / 和
php app/console cache:clear --env=dev --no-debug (on development mode)
回答by Yercalamarino
Only this worked for me rm -rf app/cache/*
只有这对我有用 rm -rf app/cache/*
回答by Dead-Man
Make sure you have defined namespace in your interface SessionHandlerInterface
确保您在接口 SessionHandlerInterface 中定义了命名空间
EX:
前任:
namespace app\cache\dev;
回答by Dedicated Manager
I was having caching issues even when using app_dev.php. I would change a route but it wouldn't update when I tried accessing it via a browser.
即使在使用 app_dev.php 时我也遇到缓存问题。我会更改路线,但是当我尝试通过浏览器访问它时它不会更新。
I tried commenting out the anything that had cache in it (as stated above). None of that worked.
我尝试注释掉其中包含缓存的任何内容(如上所述)。这些都没有奏效。
If I ran the console cache:clear it would fix it, but the next routing change would break again. I had to run cache:clear with every save, which was ridiculous.
如果我运行控制台缓存:清除它会修复它,但下一个路由更改会再次中断。我不得不在每次保存时运行缓存:清除,这很荒谬。
My issue turned out that because I was working remotely over SFTP, PHP Storm (my editor) was "preserving timestamp" in its deployment configuration. Once I changed that configuration the issues went away. Apparently there is some caching going on that is looking at the file timestamps, even in the dev environment.
我的问题原来是因为我通过 SFTP 远程工作,所以 PHP Storm(我的编辑器)在其部署配置中“保留时间戳”。一旦我更改了该配置,问题就消失了。显然,即使在开发环境中,也有一些缓存正在查看文件时间戳。

