LoginSignup
4
0

More than 5 years have passed since last update.

phpのclass名は case insensitive という話

Last updated at Posted at 2018-03-28

人のソースを追っていてどうしても宣言が見つからなくて、、、

知らなかった・・・

<?php

class myvar
{
    public static $foo = 1;
}

echo MYVAR::$foo;     // 1

大文字小文字違うclassがあることは知ってたけど、まさか同じとは思わずハマってしまった

Capital letters in class name PHP - Stack Overflow

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

Linuxでcase insensitiveなら、もう何のOSでも case insensitiveなんじゃなかろうか。

instanceof で調べてわかった

これをやってわかりました

<?php

class myvar
{
    public static $foo = 1;
}

$ins = new myvar();

print_r($ins instanceof myvar); // 1
print_r($ins instanceof MYVAR); // 1

ちなみに

class_alias() っていう落とし穴もあるよ!!

4
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
0