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

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

问题描述

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



为什么是这种情况?



编辑 - 这不是一个巨魔类型的文章 - 我认为每次我使用的语言!


< div语言有些有机地增长,所以函数的命名是随机的。许多不同的格式由于向后兼容的原因而被保留。



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

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

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

$有趣的是,PHP似乎在内部与这些顺序一致,因为所有的字符串函数似乎使用 $ haystack,$ needle while array函数是另一回事,但这可能需要一点习惯对一个新的PHP人。有一个很好的 ExpressionEngine上的帖子,更详细地讨论了这个特殊的问题,以及有关PHP错误列表的讨论



随着语言的成熟,有很多尝试来实现一个更加严格和一致的命名约定 - 从 Zend Framework文档


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



filterInput()



getElementById b $ b

对于稍微不同的操作,从 20个可能的原因,为什么PHP函数名称和参数奇怪




  • PHP会将API和人员粘在一起,有时候会变得混乱。


  • <


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


  • PHP还有其他问题需要解决。

  • b $ b

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天全站免登陆