Capital letters in class name PHP

前端 未结 3 1830
慢半拍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:37

    Classnames in PHP are not case sensitive (that doesn't depend on the operating system)

    class myclass {}
    
    $x = new MYclaSS;
    
    var_dump($x);
    
    object(myclass)#1 (0) {
    }
    

    so as general advice: You shouldn't start and try to mix something there :)

    Code like this should not work:

    class ab {}
    
    class AB {}
    
    Fatal error: Cannot redeclare class AB in ... on line x
    

提交回复
热议问题