4 ms·
The thing I hate about php is the inconsistency and unpredictability for new-to-php developers. camelCase? snake_case? nocase? Who knows what the global functi
by fatboy 6y ago
The thing I hate about php is the inconsistency and unpredictability for new-to-php developers.
camelCase? snake_case? nocase? Who knows what the global function will be.
And who knows what order the arguments should go in. Sometimes the array is first, sometimes not (in array iterating functions like map).
The thing that got my goat the most however was that referencing an undefined variable merely caused a warning, but referencing an undefined key in an array borked it.
And what's with arrays and maps being the same thing?!
- simion314 6y agoFYI when you start a PHP project you need to change your dev machine php.ini to be super strict, so all warrnings should just error out. The inconsistency seems to have it's logic and at that time was consistent and made sense, you need a good IDE to help with this. Using PHPStorm and then using PHPDoc to define your functions parameters and return type is a joy, the IDE will catch your type mistakes, show you where you missed to catch an exception and it will code complete stuff.
- stonogo 6y agoIt never made sense. The original hash bucketing mechanism for the function lookup in PHP was the length of the name of the function, so each new function was named a specific length to ensure the function list was evenly distributed across the hash table.
- simion314 6y agoCan you link or be more clear? I assumed you are talking about the array and string related functions that are not consistent in argument order.
- cesarb 6y agoThe parent comment is referring to https://news-web.php.net/php.internals/70691 https://news-web.php.net/php.internals/70691 (found via https://news.ycombinator.com/item?id=6919216 https://news.ycombinator.com/item?id=6919216). Quoting from that link: Well, there were other factors in play there. htmlspecialchars was a very early function. Back when PHP had less than 100 functions and the function hashing mechanism was strlen(). In order to get a nice hash distribution of function names across the various function name lengths names were picked specifically to make them fit into a specific length bucket. This was circa late 1994 when PHP was a tool just for my own personal use and I wasn't too worried about not being able to remember the few function names.
- simion314 6y agoThanks, I did not know that bit of history.
- fatboy 6y agoThanks for the tips! I suspect PHPStorm/Doc may be the only one that flies for the legacy codebase I sometimes get involved with - turning warnings into errors would be suicidal...
- simion314 6y agoYou don't turn warnings into error on production but it will help to have them enabled on your local machine, otherwise errors are ignored and you would waste your time debugging weird issues. You can do this per file too using the "ini_set" https://www.php.net/manual/en/function.ini-set.php https://www.php.net/manual/en/function.ini-set.php