Closed
Description
General issue to track naming suggestions:
Let me start with string functions...
General name conventions:
context | current name | suggestion | reason |
---|---|---|---|
* | $string | $str | $str is a very common abbreviation, and effectively just repeating the typehint. Writing $string over $str as parameter name has no intrinsic clarity gain. Also e.g. strtr() uses $str, while str_split uses $string. |
string functions | $data | $str | $data suggests, without reading the source signature, that something may be not just a string. |
* | $is_ prefix | $ | Drop is_ prefixes for booleans, they are anyway given by the type; is_something: true in a named function call does not help over something: true |
comparing functions | $frist, $second | $str1, $str2 | E.g. similar_text, keep it consistent with strcmp(). (for non-string types, obviously not a "str" prefix) |
function | current parameters | suggestion | reason |
---|---|---|---|
str_i?replace | $search, $replace, $subject, $count | $from, $to, $subject | is $search what shall be serached for or in? Also mirroing strtr() then |
strc?spn | $subject, $mask, $start, $length | $str, $mask, $start, $length | $subject does not provide any clarity over generic short $str |
addcslashes | $str, $charlist | $str, $mask | consistency with $mask from strspn |
chunk_split | $body, $chunklen, $end | $str, $chunklen, $end | The notion of $body is derived from the usage in mails, but the function is far more generic than that |
[lr]?trim | $str, $character_mask | $str, $mask | consistency with $mask from strspn |
(sha1|md5)(_file) | $filename/$str, $raw_output | $filename/$str, $binary | what is "raw" even supposed to mean? We want binary, i.e. not a hex representation |
str_word_count | $string, $format, $charlist | $str, $format, $mask | consistency with $mask from strspn |
strpbrk | $haystack, $char_list | $haystack, $mask | consistency with $mask from strspn |
substr_compare | $main_str, $str, $offset, $length, $case_insensitivity | ??, ??, $offset, $length, $case_insensitivity | Not sure, but $main_str and $str is weird - maybe needle and haystack? |