简体   繁体   English

PHP5.5:致命错误:无法重新声明课程

[英]PHP5.5: Fatal error: Cannot redeclare class

since I upgraded from PHP 5.2 to 5.5 I get an error I don't understand by now. 自从我从PHP 5.2升级到5.5后,我得到了一个我现在不明白的错误。

Fatal error: Cannot redeclare class sessionHandler in ... on line ...

Well before updating the PHP version this error didn't raise and redeclaring a class should be an error independent from PHP version as I guess. 在更新PHP版本之前,这个错误没有引发,重新声明一个类应该是一个独立于PHP版本的错误,我想。 Further I always use require_once() which should help to avoid a mistake on that. 此外,我总是使用require_once(),这应该有助于避免错误。

So just to make sure it doesn't be redeclared, I added a backtrace code block before that class declaration. 所以为了确保它不被重新声明,我在该类声明之前添加了一个回溯代码块。 So hopefully, I thought it would output twice, but I get only one backtrace output at all. 所以希望,我认为它会输出两次,但我只得到一个回溯输出。 Therefore it gets declared only once from my point of few. 因此,从我的观点来看,它只被宣布一次。

Do I miss something? 我错过了什么吗? Any idea how to find the "real" issue? 知道如何找到“真正的”问题吗?

Class "SessionHandler" already exists in the namespace as it's a class in PHP - http://php.net/manual/en/class.sessionhandler.php 类“SessionHandler”已经存在于命名空间中,因为它是PHP中的一个类 - http://php.net/manual/en/class.sessionhandler.php

Looks like the class was included in PHP 5.4 so it explains everything. 看起来这个类包含在PHP 5.4中,所以它解释了一切。

Try to think of some other name for the class or define a namespace. 尝试为该类考虑其他名称或定义名称空间。 If you create a namespace, something like.. 如果你创建一个命名空间,像...

namespace App;
class sessionHandler {
....

you won't get the error anymore but you will need to use App\\sessionHandler whenever you're referring to your own class. 你不会再得到错误了,但是每当你提到自己的类时,你都需要使用App \\ sessionHandler。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM