
本文介绍了PHP:不能重新声明类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所以我在这种情况下有3个类。
Connection.php
Engineer.php
Status.php
工程师和状态类实际上都使用连接。没有问题,但现在我在一个页面中使用这两个类
致命错误:Can not redeclare类连接
有没有办法?在这两个类中,我需要从连接类进行db访问。
谢谢,
Jonesy
$而不是使用include()使用require_once()来将Connection.php导入到Engineer.php和Status.php中。 $ b $ b
So I have 3 classes in this situation.
Connection.php
Engineer.php
Status.php
Both Engineer and Status classes actually use connection. Hasn't been a problem but now that I'm using both classes in a page I'm getting
Fatal error: Cannot redeclare class Connection
Is there a way round this? In both classes I need db access from the connection class.
Thanks,
Jonesy
解决方案
instead of using include() use require_once() for importing Connection.php into Engineer.php and Status.php.
这篇关于PHP:不能重新声明类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!