3 ms·
I for one would rather see common utilities move into proper naming and static classing with proper returns. For instance, strpos(string haystack, string needle
by pathartl 8y ago
I for one would rather see common utilities move into proper naming and static classing with proper returns. For instance, strpos(string haystack, string needle) will return the position of needle in haystack as an int if found. If not, it returns false. To me, the proper thing in this scenario is to either return an int (even -1 is fine for not found) or throw an exception.
There's inconsistencies in typing of what is returned. There's nothing wrong with loose typing, especially in the place that PHP is used. It's just that the PHP API regularly returns not what you'd expect.
Throw into the mix that the built in simple-functions are all over the place (https://www.php.net/manual/en/ref.strings.php https://www.php.net/manual/en/ref.strings.php). Seriously, there's str_replace, strpos, and parse_str. These could easily be solved by doing something similar to C#'s naming by changing it to something like String.Replace, String.IndexOf, String.Parse.