3 ms·
Speaking as someone who has used PHP for years, I find a lot of the criticism is from people who are merely recycling second-hand opinions, or haven't used it s
by blowski 4y ago
Speaking as someone who has used PHP for years, I find a lot of the criticism is from people who are merely recycling second-hand opinions, or haven't used it since both they and the language were very different. Other criticisms are true of pretty much all programming, hardly unique to PHP.
The criticisms I would say are both still true of PHP, and aren't true of all languages:
* The PSR-4 pattern of "one class per file" encourages a lot of files.
* There's no concept of a module, where classes and methods can be public within that module, but private outside of it. This makes it hard to expose an interface.
* It's pretty verbose, with lots of boilerplate, brackets, and semi-colons.
* Installing extensions makes it difficult to configure environments.
All that being said, PHP would still be my go-to language for doing a low-traffic application doing mostly CRUD. It's a stable and reliable language, performant for many use cases, with some fabulous frameworks and libraries.
- user3939382 4y ago> It's pretty verbose, with lots of boilerplate We recently got constructor promotion which has been really nice https://stitcher.io/blog/constructor-promotion-in-php-8 https://stitcher.io/blog/constructor-promotion-in-php-8 > Installing extensions makes it difficult to configure environments. At least the way I do it, required extensions are just 1 line in a Dockerfile.
- blowski 4y agoYes, that's been brilliant. Read-only properties too. A typical PHP file now includes: <?php declare(strict_types=1); namespace App\Something; use App\Services\Bar; final class Foo { public function __construct(private readonly Bar $bar) {} public function doSomething(): string { return $this->bar->baz(); } } And I end up with a lot of PHP files that look very simlar. I'd love some defaults here. * strict types * namespaces to be autocalculated (since PSR-4 means it has to be in that namespace anyway) * private, final and readonly both default to true * The opening PHP tag * Relative namespace * Plus all those brackets and words that duplicate information. If it has brackets, it's a function. An empty function body doesn't need curly brackets. I recognise this is a backwards-compatbility thing, so it's not as easy as "just do it". But I'd love a PHP file that looked lke: class Bar { __construct(Services\Baz $baz) public doSomething(): string { return $this->baz->bar(); } } But again, this is me waxing lyrical. I still prefer PHP to Python, but I do like Python's expressiveness.