0

I just noticed that in my code I have both something like:

$domdoc = new DOMDocument('1.0', 'utf-8');

and

$domdoc = new DomDocument('1.0', 'utf-8');

... apparently since I've copypasted from different examples.

However, if I remember correctly, PHP is case-sensitive, so DOMDocument should not be the same as DomDocument?! Although, when I run the code with both instances in PHP 5.5.9, it seems to work - no complaints are raised...

So, can anyone explain whether DOMDocument is alias of DomDocument (or vice versa) - or are these similar, but different classes?

sdaau
  • 36,975
  • 46
  • 198
  • 278
  • Thanks @Daan - had no idea about that; feel free to post that as an answer, I'll accept it... – sdaau Aug 25 '16 at 14:21
  • 3
    http://stackoverflow.com/questions/33273941/php-case-sensitivity – Marc B Aug 25 '16 at 14:21
  • 1
    class names themselves AREN'T case sensitive, but if you're using an autoloader and running on a case-sensitive file system, then you may run into case issues, if the autoloader doesn't normalize cases. – Marc B Aug 25 '16 at 14:22
  • 1
    But don't make a habit of mixing case on class names. Sooner or later it will cause mistakes attempting the same with array keys or variable names, which are case-_sensitive_ unlike functions and classes. – Michael Berkowski Aug 25 '16 at 14:22
  • 1
    Conventionally (inasmuch as PHP has any convention) keep your functions lower-cased and classes "studly cased" (begin with upper, use an upper for the start of new words). DOMDocument is an ambiguous one because it begins with an acronym -- you'll see it done both ways as you've noticed already. Be consistent within your own code however you choose to case it (I recommend doing it as [in its documentation](http://php.net/manual/en/class.domdocument.php) as `DOMDocument`) – Michael Berkowski Aug 25 '16 at 14:26

2 Answers2

1

PHP is case insensitive for the class naming.

Daan
  • 12,099
  • 6
  • 34
  • 51
0

DomDocument is a powerful library of PHP-5 to create XML. DOMDocument Represents an entire HTML or XML document; serves as the root of the document tree.

Leo
  • 13
  • 3
  • Thanks @Leo, but I'm not sure whether this distinction is correct, any links or an example to back it up? In any case, in my OP I can instantiate a class object regardless if I use `new DOMDocument` or `new DomDocument`, and I don't really have to refer to the root ?! – sdaau Aug 25 '16 at 14:32