开发者

how to avoid Cannot redeclare class for 2 diffrent classes with same name

开发者 https://www.devze.com 2023-01-19 02:14 出处:网络
I\'m trying to include some functions from phpBB board to my application like a single login. But if i include the common.php it says \"Cannot 开发者_如何学运维redeclare class user\", because my appli

I'm trying to include some functions from phpBB board to my application like a single login. But if i include the common.php it says "Cannot 开发者_如何学运维redeclare class user", because my application already has a class user. Is there a way to avoid this ? I tried a little with namespaces, but I never worked with them.

So I need a way to include 2 classes with the same name.


Namespaces are the only way.


As mentioned in the other answers to this question, there is no way of getting around this without renaming your class or going through the fuss of getting namespaces working (e.g. ensuring you have the right PHP version).

A good general habit is to namespace your class names by habit. If you look at, for instance, Zend packages, you will see that every class name is prefixed by Zend_, e.g. Zend_Mail, Zend_Mime, Zend_Mime_Part. This means that (a) there is a logical relationship between classes that have related functions and (b) that classes are unlikely to conflict with those made by you or by another framework. This pattern is followed by other projects, such as PEAR.

This requirement is made obsolete by the introduction of PHP 5.3. However, 5.3 is not yet widely adopted, especially by shared hosting providers, and this solution may well be a good one for your current situation.


Just rename your class. not a big deal

0

精彩评论

暂无评论...
验证码 换一张
取 消