💭 PHP from the Perspective of a JavaScript Developer (JavaScript Tooling Is Awesome)
After a long pause, I wrote a couple of lines of PHP code the other day. This is a summary of my experience.
A couple of years ago, I considered myself more of a PHP developer than a JavaScript developer. So I was shocked how much I had forgotten. On the other hand, the last time I wrote PHP daily, it was a very different PHP. Then, I mainly hacked around in Drupal. Nowadays, at my workplace, we write professional PHP. So the first thing I wanted to do was start with a PHPUnit test.
And this is where the first surprise awaited me: where is the watch mode? It turned out: there is none! But a colleague helped me out and sent me a link to phpunit-watcher by Spatie. Overall, PHPUnit seemed okay, but a couple of things are more polished in Jest. Especially mocking! It turns out you simply can't mock static methods in PHP, for example.
Another interesting experience was that the linter didn't show line numbers for the problems it found. But it was not a huge deal because the auto-fix worked fine.
I use VSCode as my primary editor, and it turns out that it is not very well equipped for PHP out of the box. But I'm sure that this is only a matter of installing the right plugins.
The built-in type system in PHP seems fine. But I had problems with it when writing mocks in tests. For example, it turns out you can't typecast custom types.
Working with named key arrays is weird. I miss the separation between objects and arrays from JavaScript. And also much prefer the dot notation object.key
over $array['key']
.
Overall, after one day—so take this with a grain of salt—of working with PHP again, the language seems cumbersome. The tooling feels less sophisticated to me than what we have in the JavaScript world. On the other hand, I think there are much more mature frameworks for PHP. Although AdonisJS seems to be on track to be a worthy Node alternative to Laravel.
Working with PHP for one day makes me appreciate the JavaScript ecosystem much more again. There are flaws, for sure, but overall we have excellent tooling. But we have to remind ourselves that we don't need to use all of it in every project.