开发者

What is the PHP function naming and argument order logic/convention? [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 10 years ago.

Are the functions named, and their arguments ordered randomly in PHP? I find it real hard to remember which function is how, and always find myself refe开发者_运维知识库rring the manual. What do you do to remember them without having to refer the manual every time?

few examples:

array_map(callback, array) but array_filter(array, callback). When dealing with strings strstr(), strpos() and substr() has no underscores but str_replace(), str_pad() and str_split() does. and in most cases, the string is accepted as the first argument but in explode() the string is the second argument.


PHP has quite a few inconsistencies in the internal functions, just something you have to get used to - always have the function reference open when coding.

This is an acknowledged problem, but unresolvable without breaking huge amounts of existing code, ie. all of it, as the functions affected are highly used ones for the most part. :-/


I find it nice to have a bookmark keyword search on firefox http://php.net/%s

So this way I can type in the URL bar: p function_name, and firefox automatically opens http://php.net/function_name, which is the php function reference manual for the function...

I disagree with Orbling when he says the inconsistency problem is unresolvable... new function aliases could be made to reorganize all of php functions that could be used in new code... for instance having a prefix or some standard way of grouping the functions...


  1. English is somewhat inconsistent in the same way. Sir Bernard Shaw once noted that a word that pronounced "fish" may be written in English as "ghote".

  2. PHP was grown as any other natural language. With bugs, mistakes and inconsistency.

  3. Nobody forbids you from writing your own abstraction library with whatever naming and syntax rules you choose.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜