为什么PHP中的内置函数如此随机地命名? [英] Why are the built in functions in PHP named so randomly?

查看:223
本文介绍了为什么PHP中的内置函数如此随机地命名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

似乎没有真正的模式,函数的命名方式,str_replace,strrpos,strip_tags,stripslashes只是一些。



为什么是这样的情况?



编辑 - 这不是一个巨魔类型的帖子 - 只是我认为每次我使用这种语言!

解决方案

PHP语言已经有了一些有机的变化,所以功能的命名是随意的部分。许多不同的格式被保留用于向后兼容性的原因。



有点离题,但除了功能命名的问题,另一个不幸的副作用有机语言的增长在参数排序中是明显不一致的,例如考虑功能 in_array strstr

  bool in_array(mixed $ needle,array $ haystack [,bool $ strict ])

string strstr(string $ haystack,mixed $ needle [,bool $ before_needle = false])

$ b $有趣的是,PHP似乎在内部符合这些顺序,因为所有的字符串函数似乎都使用 $ haystack,$ needle 而数组函数是另一种方式,但是这可能需要一些习惯用于新的PHP的人。有一个很好的在ExpressionEngine上发布,更详细地谈论这个特别的怪癖,以及一个<一个href =http://bugs.php.net/bug.php?id=37088 =noreferrer>关于PHP错误列表的讨论。



随着语言的成熟,有各种各样的尝试来实现更加僵硬和一致的命名约定 - 从 Zend Framework文档


函数名必须始终以小写字母开头。当一个函数名称由多个单词组成时,每个新单词的第一个字母必须大写。这通常被称为camelCase格式。



filterInput()



getElementById()


为什么PHP函数名称和参数是奇怪的20个可能的原因



PHP的API和人类一起粘在一起,有时候这会变得凌乱


  • PHP功能已经在许多情况有时候喝醉了


  • PHP函数命名算法仍然是一个秘密,不能破解


  • p> PHP选择给人一些有趣的抱怨/博客/笑话


  • PHP还有其他问题要解决



  • It seems that there is no real pattern to the way functions are named, str_replace, strrpos, strip_tags, stripslashes are just some.

    Why is this the case?

    EDIT - this wasn't meant as a "troll" type post - just something that I think everytime I use the language!

    解决方案

    The PHP language has grown somewhat organically, so the naming of functions is haphazard in parts. Many of the different formats are retained for backwards-compatibility reasons.

    A slight digression, but in addition to the issues with function naming, another unfortunate side-effect of the organic growth of the language is an apparent inconsistency in argument ordering, e.g. consider the functions in_array and strstr:

    bool in_array (mixed $needle, array $haystack [, bool $strict])
    
    string strstr (string $haystack, mixed $needle [, bool $before_needle=false])
    

    Funnily enough, PHP seems to be internally consistent with these orderings in that all string functions seem to use $haystack, $needle while array functions are the other way around, but this can take a bit of getting used to for someone new to PHP. There's a good post on ExpressionEngine talking about this particular quirk in more detail, as well as a discussion on the PHP bugs list.

    As the language matures, there are various attempts to implement a more rigid and consistent naming convention - from the Zend Framework Documentation:

    Function names must always start with a lowercase letter. When a function name consists of more than one word, the first letter of each new word must be capitalized. This is commonly called "camelCase" formatting.

    filterInput()

    getElementById()

    For a slightly different take, from 20 possible reasons why PHP function names and parameters are weird:

    • PHP glues APIs and humans together, and sometimes this gets messy

    • PHP functions have been developed under many circumstances, sometimes drunk

    • PHP function naming algorithm still remains a secret and cannot be cracked

    • PHP chose to give people something fun to complain/blog/laugh about

    • PHP has other problems to solve

    这篇关于为什么PHP中的内置函数如此随机地命名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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