如果两个类位于不同的文件夹中,是否可以使用相同名称的两个类? [英] Is it possible to have two classes with the same name if they're in different folders?

查看:289
本文介绍了如果两个类位于不同的文件夹中,是否可以使用相同名称的两个类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道,如果两个类在同一个子文件夹中,那么在PHP中使用相同名称的两个类是否有问题,除了明显的人为因素"是错误地编辑错误的文件之外?

I was wondering if there is anything wrong with having two classes with the same name in PHP if they're in different sub folders, other than the obvious "human factor" of editing the wrong file by mistake?

我在网上和其他地方都在寻找与此相关的其他帖子,但是我找不到任何可以回答这个特定问题的帖子.但是,我确实发现从不同文件夹自动加载类很有帮助,实际上解决了我的其他问题之一.

I have looked for other posts relating to this, here and elsewhere on the web, but I didn't find any that could answer this specific question. I did however find this Autoload classes from different folders very helpful though, and in fact it solved one of my other questions.

推荐答案

即使在同一文件夹中,也可能具有相同名称的类.

This is possible to have classes with same name even in same folder.

但是请确保您一次只在PHP脚本中加载了一个类.

But Make sure you have loaded only one class in the PHP script at a time.

不能同时将它们加载到同一脚本中.

They can not be loaded in the same script at same time.

PHP不知道您是否创建了两个具有相同名称的类,但事实是PHP不会在同一脚本中加载它们.您一次只能使用一堂课.

PHP does not know if you have created two classes with same name but the fact is PHP will not load them in same script. You can use one class at a time.

您还可以在php中查看命名空间.

You can also look at namespaces in php.

这篇关于如果两个类位于不同的文件夹中,是否可以使用相同名称的两个类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆