Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationEventAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
0
Help us understand the problem. What are the problem?

More than 3 years have passed since last update.

posted at

updated at

phpのclass名は case insensitive という話

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

知らなかった・・・

<?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() っていう落とし穴もあるよ!!

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
0
Help us understand the problem. What are the problem?