为什么 CodeIgniter 强制类的第一个字母大写?
根据创建库文档:
File names must be capitalized. For example: Myclass.php
Class declarations must be capitalized. For example: class Myclass
这是为什么?一旦它作为属性加载(例如$this->myclass->do_something()
),它就会小写。
As per the creating libraries documentation:
File names must be capitalized. For example: Myclass.php
Class declarations must be capitalized. For example: class Myclass
Why is this? Once it's loaded as a property (e.g. $this->myclass->do_something()
) it's lowercased anyway.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
“myclass”(
$this->myclass
)是该类的一个实例,而不是一个类。实例/对象是小写的,但类是大写的。调用静态函数就像 Myclass::do_something_statically() (注意大写)。
所以小写的东西是别的东西,把类变成大写会让你看到区别:)
that "myclass" thingy (
$this->myclass
) is an instance of the class, not a class.Instances / objects are lowercase, but the class is uppercase. Calling a static function would go like
Myclass::do_something_statically()
(notice the uppercase).So the lowercase thing is something else, and making the class upcase will let you see the difference :)
也许出于同样的原因,德语将名词大写。
它使人类读者更容易“解析”文本。
Maybe for the same reason German capitalizes nouns.
It make it more easy for human readers to 'parse' the text.