为什么PHP中的函数和方法不区分大小写? [英] Why are functions and methods in PHP case-insensitive?

查看:70
本文介绍了为什么PHP中的函数和方法不区分大小写?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

PHP中的函数和方法不区分大小写,如以下示例所示.

Functions and methods in PHP are case-insensitive as illustrated in the following example.

function ag()
{
    echo '2';
}

Ag();
class test {
    function clMe()
    {
        echo 'hi';
    }
}

$instance = new test;
$instance->clme();

但这不是变量的情况.有什么道理?

But that's the not case with variables. What's the rationale?

推荐答案

让我引用采访– PHP的创建者,拉斯穆斯·勒多夫(Rasmus Lerdorf)

PHP的第一个版本是一组简单的工具,我将它们组合在一起用于我的网站和几个项目.一种工具可以很好地记录到mSQL数据库,另一种则充当表单数据解释器.在我厌倦了用C编写的大约30个不同的小CGI程序之前,我将它们全部组合到一个C库中.然后,我编写了一个非常简单的解析器,该解析器将从HTML文件中挑选标记并将其替换为C库中相应函数的输出.

The first version of PHP was a simple set of tools that I put together for my Website and for a couple of projects. One tool did some fancy hit logging to an mSQL database, another acted as a form data interpreter. I ended up with about 30 different little CGI programs written in C before I got sick of it, and combined all of them into a single C library. I then wrote a very simple parser that would pick tags out of HTML files and replace them with the output of the corresponding functions in the C library.

简单的解析器逐渐发展为包含条件标记,然后包含循环标记,函数等.我丝毫没有想到我正在编写脚本语言.我只是在宏替换解析器中添加了一些功能.我仍在用C编写所有真实的业务逻辑.

The simple parser slowly grew to include conditional tags, then loop tags, functions, etc. At no point did I think I was writing a scripting language. I was simply adding a little bit of functionality to the macro replacement parser. I was still writing all my real business logic in C.

我在某处读到,由于引入的所有函数在本质上都感觉像HTML文档中的标记,并且HTML标记不区分大小写,因此他在PHP中选择的函数名称不区分大小写.稍后,该功能仍保留在语言中.

I have read somewhere that since all the functions introduced essentially felt like tags in an HTML document and since HTML tags were case insensitive, he chose function names in PHP to be case insensitive. Later on this feature remained on in the language.

这篇关于为什么PHP中的函数和方法不区分大小写?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆