What is the PHP function naming and argument order logic/convention? [closed]
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...
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".
PHP was grown as any other natural language. With bugs, mistakes and inconsistency.
Nobody forbids you from writing your own abstraction library with whatever naming and syntax rules you choose.
精彩评论