Capital letters in class name PHP

前端 未结 3 1825
慢半拍i
慢半拍i 2020-12-06 00:11

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

3条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-06 00:54

    I guess you are using some kind of lazy loading for class files, may be you are programming in a PHP framework. The secret will lie in your __autoload function. Find it.

    Check PHP manual for Autoloading.

    The following code:

    Gives an error: Cannot redeclare class File so again, the trick might be which file is included.

    Behavior of your code displays that one of the classes isn't being loaded (otherwise you'll see class redeclare error). It is probably the auto loader that first loads the file class and then when it finds definition to File it simply assumes that that it has already loaded the class (due to case insensitive behavior of PHP).

提交回复
热议问题