类名PHP中的大写字母 [英] Capital letters in class name PHP
问题描述
我的系统中有两个类。一个称为文件,第二个是File。
在我的localhost当我实例化文件我获得文件对象,但我的朋友运行相同的脚本获取文件的对象,像大写字母无法识别,文件等于文件。
是一些可配置的东西吗?
我们都在Windows上运行。我有WampServer,他有XAMPP。
I have two classes in my system. One is called file and second is File. On my localhost when i instantiate file i get file object, but my friend running the same script gets object of File like the capital letters were unrecognized and "file" was equal to "File". Is that some configurable thing? We are both running on Windows. I have WampServer, he has XAMPP.
推荐答案
PHP对类命名不区分大小写。它意味着你可以正常做 $ file = new file()
,即使该类名为 File
,反之亦然。
PHP is case insensitive for the class naming. it means you can normally do $file = new file()
even if the class is named File
and vice-versa.
你是否依赖类文件的自动加载?如果是这种情况,可能根据计算机,解释器不总是首先找到相同的文件。这将解释问题。
Are you by any chance relying on the auto loading of class files ? If this is the case, it is possible that depending on the computer, the interpreter don't always find the same file first. This will explain the problem.
我强烈建议您重命名您的课程。它总是一个坏主意,依靠case来区分两个不同的东西,按照惯例,类名总是以大写字母开头。
I strongly suggest that you rename your classes. It's always a bad idea to rely on case to differentiate two different things and by convention, class names always start with a capital letter.
如果你不能改变类名称,我建议您查看 php命名空间。
If you can't change the class names, I suggest to have a look at php namespaces.
这篇关于类名PHP中的大写字母的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!