2 ms·
The biggest grievances stem from PHP wanting to please you and convert things from one type to another even when it really, really shouldn't. Adding variadics i
by chx 9y ago
The biggest grievances stem from PHP wanting to please you and convert things from one type to another even when it really, really shouldn't. Adding variadics in 5.6, return and scalar types in PHP 7 tunes down this sort of crazy. Not fully, though. String comparison is still broken -- use strcmp() and be happy. Using anything else is dark and full of terrors. Well, at least it's not transitive https://3v4l.org/goSYX https://3v4l.org/goSYX
Further, avoid == completely, pass the strict argument to functions that do comparison like in_array(). You don't want https://3v4l.org/mcpi7 https://3v4l.org/mcpi7 to happen. You want https://3v4l.org/Yo6tI https://3v4l.org/Yo6tI instead.
Your functions in 7.1 finally can typehint for iterable (array or Traversable object) although the array_* functions still only accept arrays. There are nice little libraries papering that over and installing libraries is easier thanks to composer.
PhpStorm gives you a fantastic IDE. The language is still ridiculously easy to deploy thanks to a zero share model.
Basically: most of the landmines can be cordoned off with putting declare(strict_types=1) on top of your files or bridged over by libraries like nikic/iter. A few are left but they are easy to avoid.
- Vinnl 9y agoDoes PHP have linters or something that force you to use the practices you described? I find in Javascript that works pretty well to restrict the language to a sane subset.
- _cereal 9y agoYou can use phpmd: https://phpmd.org/ https://phpmd.org/ or phpcs: http://cs.sensiolabs.org/ http://cs.sensiolabs.org/