2 ms·
> It's pretty verbose, with lots of boilerplate We recently got constructor promotion which has been really nice https://stitcher.io/blog/constructor-promotion
by 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.